Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

cordova - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);
            }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...