Phonegap/Cordova FileTransfer - Error 3 - Android
问题描述:
我已升级到最新版本的Phonegap 3.0.0。这似乎引入了间歇性上传错误问题。Phonegap/Cordova FileTransfer - Error 3 - Android
我有一个简单的上传照片的应用程序。 我选择了一张照片,然后按上传。
随机它将返回“错误代码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);
}
我已经覆盖了更多其他人的建议,尽管我不认为它相关的因间歇性
- 加真到上传命令的末尾以启用自签名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.
更新 我发现这似乎是在为同样的问题科尔多瓦错误跟踪器没有解决方案。 https://issues.apache.org/jira/browse/CB-2293#comment-13753360
答
我有同样的问题,并通过更新新的测试OkHttp jar来完成它。 根据URL安德鲁·格里夫的建议是: https://issues.apache.org/jira/browse/CB-2293#comment-13753360
我下载OkHttpd.jar通过网址: https://github.com/square/okhttp
upzip罐子和复制所有的类文件到到Android /库/科尔多瓦-3.1.0.jar
这很好,祝你好运!
我们与版本2.6.0有相同的错误。 – kzfabi