找不到Cordova FileTransfer.upload文件

时间:2016-12-09 18:22:58

标签: cordova cordova-plugins

我尝试使用Cordova / Phonegap上传文件file-transfer-plugin,如下所示:

{ 
    test: /\.json$/,
    loader: 'json-loader',
},

这就是我得到的(来自function uploadFileFromMobile(fileURL, name, type) { function win(r) { console.log("Code = " + r.responseCode); console.log("Response = " + r.response); console.log("Sent = " + r.bytesSent); } function fail(error) { alert("An error has occurred: Code = " + error.code); console.log("upload error source " + error.source); console.log("upload error target " + error.target); } var uri = encodeURI(someURI); var options = new FileUploadOptions(); options.fileKey = "file"; //options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1); options.fileName = name; options.mimeType = type; options.headers = { 'Accept': 'application/json', 'httpMethod': 'POST' }; options.chunkedMode = false; var ft = new FileTransfer(); //fileURL = file:///storage/emulated/0/somefile.txt ft.upload(fileURL, uri, win, fail, options, true); } 函数):

fail

我想我文件的路径是错误的,但我不明白为什么。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

在代码中应用以下更改

options.headers = {
        'Accept': 'application/json'
    };

options.httpMethod: 'POST';

现在您的代码将正常运行。