我自己回答了这个问题,因为我花了很长时间才找到解决方案,而且记录得不好。
在尝试使用FileTransfer()将图像从android上的phonegap应用程序上传到远程服务器时,我在每次备用文件上传中始终收到错误代码3。
它工作一次,但是当我再次尝试时,即使没有将文件发送到服务器,它也会引发错误。
我用于文件上传的代码是:
使之起作用的关键是添加标题选项。
options.headers = {
Connection: "close"
}
options.chunkedMode = false;
完整的代码:
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.chunkedMode = false;
*options.headers = {
Connection: "close"
};*
// setup parameters
var params = {};
params.fullpath =imageURI;
params.name = options.fileName;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI(url+'/account/profile-pics'), win, fail, options);
function win(r) {
//file uploaded successfully
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
alert("upload error source " + error.source);
alert("upload error target " + error.target);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句