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.
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 code i am using for the file upload was :
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With