cordova FileTransfert在两个错误3上工作一次

时间:2017-04-14 11:37:09

标签: cordova cordova-plugins

我对cordova的fileTransfert插件有一个奇怪的问题(目标设备是Android 4.3,它适用于Android 6.0)。 我刚到两个上传一个文件。 第一个和第三个发送工作很好,但第二个返回错误代码3,并在日志中显示此错误消息:

E/FileTransfer(15179): {"target":"https:\/\/XXXX\/uploadTeamPicture","http_status":0,"code":3,"source":"file:\/\/\/storage\/emulated\/0\/Pictures\/2017_4_14\/XXXXX_14-15-00.jpeg","exception":"Write error: ssl=0x6e653128: I\/O error during system call, Broken pipe"}

这是功能

// Manage File sending
function uploadFile(webAddr,fileURL,params)
{
    // when it's finished
    var win = function (r) {

       alert("Picture has been sent correctly !","Information"); 
       $("#takePicture").hide();
       resetAppli();
       fileTrans.abord();
    };
    // if upload failed
    var fail = function (error) {
        var msg="Please take another picture \n"; 
        msg+="An error has occurred: Code = " + error.code;
        msg+="\n src:"+error.source;
        msg+="\n trgt:"+error.target;
        alert(msg);
        $("#takePicture").hide();
        resetAppli();
    };


    var uri = encodeURI(webAddr);

    var options = new FileUploadOptions();
    options.fileKey="fileToUpload";
    options.fileName=fileURL.substr(fileURL.lastIndexOf('/')+1);
    options.mimeType="text/plain";

    var headers={'headerParam':'headerValue'};

    options.headers = headers;
    options.params = params;

    //var ft = new FileTransfer();
    var ft=fileTrans;
    ft.onprogress = function(progressEvent) {
        if (progressEvent.lengthComputable) {
            //loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);
            uploadProgress(progressEvent);
            var infoProg=(progressEvent.loaded / progressEvent.total);
            console.log("Progress :" + infoProg);
        } else {
            //loadingStatus.increment();
        }
    };
    // init progress bar before sending
    initProgressBar();
    // send file
    ft.upload(fileURL, uri, win, fail, options);

}

如果有人有想法...... 非常感谢您的帮助

2 个答案:

答案 0 :(得分:0)

在此处找到解决方案: Code 3 when uploading file to S3 using FileTransfer in Phonegap on Android 4.3

只需在参数表的末尾添加true选项。

答案 1 :(得分:0)

尝试更改功能的这一行

ft.upload(fileURL, uri, win, fail, options);

对此:

ft.upload(fileURL, uri, win, fail, options, true);

这一行:

var headers={'headerParam':'headerValue'};

对此:

var headers={Connection:'close'};