0

我正在开发适用于 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.}

我错过了什么吗?

任何帮助是极大的赞赏。

4

1 回答 1

0

请检查以下代码并尝试此操作。它在科尔多瓦 2.9.0 版中运行良好。

var options = new FileUploadOptions();

options.headers = {
    Connection: "close"
}
options.chunkedMode = false;

ft.upload(imgUrl, PATH, uploadSuccess, uploadFail, options);
于 2014-01-09T12:09:37.167 回答