我正在开发适用于Android的移动应用程序。在这里我试图捕获图像并将其上传到服务器。图像第一次上传但第二次没有上传,并返回FileTransfer - 错误代码3.
我的应用程序代码位于 -
var name=window.localStorage.getItem('image_name');
var path = window.localStorage.getItem('image_path');
// initializing file transfer object
var product_ft = new FileTransfer();
var options = new FileUploadOptions();
options.fileKey="image";
options.fileName=name;
options.mimeType="image/jpeg";
var params = new Object();
params.fullpath = path;
params.name = name;
options.params = params;
options.chunkedMode = false;
// uploads image
url = "http://...";
product_ft.upload( path, url,
function(response)
{
var obj = jQuery.parseJSON(response['response']);
window.localStorage.setItem('image_server_path',obj.image_path);
},
function(error) {
//upload unsuccessful, error occured while upload.
error("Error uploading image. We're sorry for this. Can you please try again?", 'Image Not Saved');
},
options
);
LogCat显示以下错误 -
{"target":"http:\/\/...","source":"file:\/\/\/mnt\/sdcard\/DCIM\/Camera\/1378965045896.jpg","http_status":0,"code":3}
{java.io.EOFException}
{at com.squareup.okhttp.internal.Util.readAsciiLine(Util.java:314)}
{at com.squareup.okhttp.internal.http.RawHeaders.fromBytes(RawHeaders.java:301)}
{at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:130)}
{at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:630)}
{at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:385)}
{at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:334)}
{at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:534)}
{at org.apache.cordova.FileTransfer$1.run(FileTransfer.java:455)}
{at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)}
{at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)}
{at java.lang.Thread.run(Thread.java:856)}
{Failed after uploading 26517 of 26517 bytes.}
我错过了什么吗?
非常感谢任何帮助。
答案 0 :(得分:0)
请检查以下代码并尝试此操作。它在cordova版本2.9.0中运行良好。
var options = new FileUploadOptions();
options.headers = {
Connection: "close"
}
options.chunkedMode = false;
ft.upload(imgUrl, PATH, uploadSuccess, uploadFail, options);