我尝试使用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
我想我文件的路径是错误的,但我不明白为什么。任何人都可以帮助我吗?
答案 0 :(得分:1)
options.headers = {
'Accept': 'application/json'
};
options.httpMethod: 'POST';
现在您的代码将正常运行。