Phonegap 文件传输图片在所有其他图片上失败:FileTransfer 上传错误代码 3 [英] Phonegap File Transfer of picture fails on every other picture: Error code 3 with FileTransfer upload
本文介绍了Phonegap 文件传输图片在所有其他图片上失败:FileTransfer 上传错误代码 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我自己回答了这个问题,因为我花了很长时间才找到解决方案,而且没有很好地记录.
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 上传图片a> android 上的应用程序到远程服务器我在每个备用文件上传时不断收到错误代码 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;
完整代码:
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 文件传输图片在所有其他图片上失败:FileTransfer 上传错误代码 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文