gpt4 book ai didi

android - Phonegap/Cordova 文件传输 - 错误 3 - Android

转载 作者:太空狗 更新时间:2023-10-29 13:28:44 26 4
gpt4 key购买 nike

我已经升级到最新版本的 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 以启用自签名 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 tracker 上发现了同样的问题,但没有解决方案。 https://issues.apache.org/jira/browse/CB-2293#comment-13753360

最佳答案

我有同样的问题,并通过更新最新的测试 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

很好,祝你好运!

关于android - Phonegap/Cordova 文件传输 - 错误 3 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18502467/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com