【问题标题】:cordova-plugin-file-transfer upload appearing as GET request even though httpMethod set即使设置了 httpMethod,cordova-plugin-file-transfer 上传也显示为 GET 请求
【发布时间】:2020-03-12 18:42:16
【问题描述】:

我正在尝试在我的应用中上传相机拍摄的图像。我正在为我的应用程序使用cordova-plugin-file-transfer,我正在尝试将图像数据发送到我的服务器进行存储(PHP)。

我已经设置了这些选项:

const options: FileUploadOptions = {
    fileKey: 'file',
    fileName: imageData.substr(imageData.lastIndexOf('/') + 1),
    headers: {},
    httpMethod: 'POST',
    chunkedMode: false,
    params: { action : 'INSERT', lineid : this.lineId },
};

this.fileTransfer.upload(imageData, encodeURI(url.replace('https', 'http') + 'pages/attachments.php'), options).then(data => {
    console.log(data);
}, error => {
    console.log(error);
});

但是,我的服务器似乎将此请求作为 GET 方法而不是 POST 接收,因此它没有在我的服务器端通过正确的上传过程。

我错过了什么吗?

【问题讨论】:

    标签: cordova ionic-framework upload file-transfer


    【解决方案1】:

    看起来插件强制上传功能使用'PUT''POST'

    https://github.com/apache/cordova-plugin-file-transfer/blob/dc8fbd78a234bd88450ebe01835c60371bc2cf8e/www/FileTransfer.js#L127-L131

    您的服务器端代码似乎有问题。检查您正在访问的端点并从那里进行调试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-10
      • 2015-09-09
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      相关资源
      最近更新 更多