簡體   English   中英

Phonegap / Cordova FileTransfer - 錯誤3 - Android

[英]Phonegap/Cordova FileTransfer - Error 3 - Android

我已升級到最新版本的Phonegap 3.0.0。 這似乎引入了間歇性上傳錯誤問題。

我有一個上傳照片的簡單應用程序。 我選擇了一張照片,然后推送上傳。

隨機它將返回“錯誤代碼3”。 這是我所理解的連接問題。 在代碼中我輸出上傳的進度。 錯誤隨機發生在上傳的不同階段。

代碼的基本精簡版本是

function getPhoto(source) {
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: destinationType.FILE_URI,
        sourceType: source });
}

function onPhotoDataSuccess(img) {
    imgUrl = img;
    $('#smallImage').attr('src',imgUrl);
}

function doUpload() {

    ft.onprogress = function(progressEvent) {
        if (progressEvent.lengthComputable) {
                var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100);
                $("#status").text("Uploading: " + perc + "%");
        } else {
                if($("#status").text() == "") {
                    $("#status").text("Uploading");
                } else {
                    $("#status").text( $("#status").text() + ".");
                }
        }
    };

    var options = new FileUploadOptions();
    options.fileKey="image";
    options.fileName=imgUrl.substr(imgUrl.lastIndexOf('/')+1);
    options.mimeType="image/jpeg";
    options.chunkedMode = false;

    ft.upload(imgUrl, baseURL + "?do_upload", uploadSuccess, uploadFail, options, true);
}

我已經涵蓋了其他人提出的建議,盡管由於間歇性,我認為它沒有相關性

  • 添加true到upload命令的末尾以啟用自簽名SSL。 我還是不使用SSL。
  • 更改了config.xml中的訪問源
  • 禁用分塊模式

有誰知道它還能是什么?

更新:

我設法在VD下發生錯誤,這給了我日志

08-29 15:06:55.172: D/FileTransfer(531): upload content://media/external/images/media/14 to http://exampledomain.com?page=do_upload
08-29 15:06:55.172: D/FileTransfer(531): fileKey: image
08-29 15:06:55.172: D/FileTransfer(531): fileName: 14
08-29 15:06:55.172: D/FileTransfer(531): mimeType: image/jpeg
08-29 15:06:55.172: D/FileTransfer(531): params: {}
08-29 15:06:55.172: D/FileTransfer(531): trustEveryone: true
08-29 15:06:55.172: D/FileTransfer(531): chunkedMode: false
08-29 15:06:55.172: D/FileTransfer(531): headers: null
08-29 15:06:55.172: D/FileTransfer(531): objectId: 1
08-29 15:06:55.172: D/FileTransfer(531): httpMethod: POST
08-29 15:06:55.192: D/FileTransfer(531): Content Length: 15007
08-29 15:06:55.202: D/FileTransfer(531): Sent 15007 of 15007
08-29 15:06:55.202: W/PluginManager(531): THREAD WARNING: exec() call to FileTransfer.upload blocked the main thread for 54ms. Plugin should use CordovaInterface.getThreadPool().
08-29 15:06:55.212: W/FileTransfer(531): Error getting HTTP status code from connection.
08-29 15:06:55.212: W/FileTransfer(531): java.io.EOFException
08-29 15:06:55.212: W/FileTransfer(531):    at com.squareup.okhttp.internal.Util.readAsciiLine(Util.java:314)
08-29 15:06:55.212: W/FileTransfer(531):    at com.squareup.okhttp.internal.http.RawHeaders.fromBytes(RawHeaders.java:301)
08-29 15:06:55.212: W/FileTransfer(531):    at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:130)
08-29 15:06:55.212: W/FileTransfer(531):    at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:630)
08-29 15:06:55.212: W/FileTransfer(531):    at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:385)
08-29 15:06:55.212: W/FileTransfer(531):    at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:334)
08-29 15:06:55.212: W/FileTransfer(531):    at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:534)
08-29 15:06:55.212: W/FileTransfer(531):    at org.apache.cordova.filetransfer.FileTransfer$3.run(FileTransfer.java:444)
08-29 15:06:55.212: W/FileTransfer(531):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-29 15:06:55.212: W/FileTransfer(531):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-29 15:06:55.212: W/FileTransfer(531):    at java.lang.Thread.run(Thread.java:856)
08-29 15:06:55.223: E/FileTransfer(531): {"target":"http:\/\/exampledomain.com\/?page=do_upload","source":"content:\/\/media\/external\/images\/media\/14","http_status":0,"code":3}
08-29 15:06:55.223: E/FileTransfer(531): java.io.EOFException
08-29 15:06:55.223: E/FileTransfer(531):    at com.squareup.okhttp.internal.Util.readAsciiLine(Util.java:314)
08-29 15:06:55.223: E/FileTransfer(531):    at com.squareup.okhttp.internal.http.RawHeaders.fromBytes(RawHeaders.java:301)
08-29 15:06:55.223: E/FileTransfer(531):    at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:130)
08-29 15:06:55.223: E/FileTransfer(531):    at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:630)
08-29 15:06:55.223: E/FileTransfer(531):    at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:385)
08-29 15:06:55.223: E/FileTransfer(531):    at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:334)
08-29 15:06:55.223: E/FileTransfer(531):    at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:534)
08-29 15:06:55.223: E/FileTransfer(531):    at org.apache.cordova.filetransfer.FileTransfer$3.run(FileTransfer.java:444)
08-29 15:06:55.223: E/FileTransfer(531):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-29 15:06:55.223: E/FileTransfer(531):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-29 15:06:55.223: E/FileTransfer(531):    at java.lang.Thread.run(Thread.java:856)
08-29 15:06:55.223: E/FileTransfer(531): Failed after uploading 15007 of 15007 bytes.

更新我發現在沒有解決方案的Cordova bug跟蹤器上出現了同樣的問題。 https://issues.apache.org/jira/browse/CB-2293#comment-13753360

我有同樣的問題,並通過更新newtest OkHttp jar來完成它。 根據Andrew Grieve的URL建議: https//issues.apache.org/jira/browse/CB-2293#comment-13753360

我通過URL下載OkHttpd.jar: https//github.com/square/okhttp

上傳jar並將所有類文件復制到android / libs / cordova-3.1.0.jar中

好吧,祝你好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM