Phonegap文件传输的图片在每一个其他图片失败:错误代码3与FileTransfer上传 [英] Phonegap File Transfer of picture fails on every other picture: Error code 3 with FileTransfer upload
问题描述
我自己回答了这个问题,因为它花了我很长时间找到它的解决方案,它没有记录得很好。
I answered this question myself since it took me a long time to find the solution for it and it wasn't documented very well.
推荐答案
尝试使用 FileTransfer() 上传来自 phonegap 的图片应用程式到远端伺服器,我在每次备用档案上传时持续收到错误代码3 。
它工作一次,但是当我再次尝试时,它会抛出一个错误,甚至不会发送到服务器。
While trying to use FileTransfer() to upload images from a phonegap app on android to a remote server i kept getting an error code 3 on every alternate file upload.
It worked once but instantly when i tried again it would throw an error without even sending the file to the server.
我用于文件上传的代码是:
使它工作的关键是添加一个标题选项
The key to making it work was to add a header option.
options.headers = {
Connection: "close"
}
options.chunkedMode = false;
完整代码:
The complete code :
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);
}
这篇关于Phonegap文件传输的图片在每一个其他图片失败:错误代码3与FileTransfer上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!