PhoneGap的图片上传的作品只有一次 [英] Phonegap Image Upload works only once

查看:138
本文介绍了PhoneGap的图片上传的作品只有一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要将照片上传到服务器。这上传的第一个拍摄的照片时的伟大工程。当我拍摄的另一张照片,上载将失败。

my app needs to upload photos to a server. This works great when uploading the first captured photo. When I capture another photo, the upload fails.

下面是我的code:

    // Upload files to server
function uploadFile(mediaFile) {

    $.mobile.loading( 'show' );
    var path = mediaFile;
    alert(path);

    var options = new FileUploadOptions();
    options.mimeType="image/jpeg";

    var params = new Object();
    params.fullpath = path;
    params.eventID = eventID;


    options.params = params;
    options.chunkedMode = true;

    var ft = new FileTransfer();
    ft.upload( path, "http://dev.tellthedj.de/db/uploadPhoto.php",
        function(result) {
            $.mobile.loading( 'hide' );
            alert("Foto erfolgreich hochgeladen");   

            // Geschossenes Foto aus Cache löschen
            var file = new FileEntry(); 
            file.fullPath = mediaFile;

            file.remove(success, fail);

            function success(){
                alert("success");
            }

            function fail(){
                alert("cache löschen nicht erfolgreich")
            }

        },
        function(error) {
            $.mobile.loading( 'hide' );
            alert("Upload nicht erfolgreich. Bitte checke deine Internet-Verbindung: ");
            console.log(error.message);
        },
        options
        );
}

媒体文件是所捕获的相片中的高速缓存文件夹的位置。 第二张照片我要一直上传称之为上传nicht erfolgreich ......我在LogCat中得到这个错误

mediaFile is the location of the captured photo in cache folder. The second photo I want to upload always calls "Upload nicht erfolgreich..." and i got this error in LogCat

07-25 08:59:11.980: E/FileTransfer(6783): {"target":"http:\/\/dev.tellthedj.de\/db\/uploadPhoto.php","source":"file:\/\/\/storage\/sdcard0\/Android\/data\/com.phonegap.getting.started\/cache\/1374735548710.jpg","http_status":0,"code":3}
07-25 08:59:11.980: E/FileTransfer(6783): java.io.EOFException
07-25 08:59:11.980: E/FileTransfer(6783):   at com.squareup.okhttp.internal.Util.readAsciiLine(Util.java:314)
07-25 08:59:11.980: E/FileTransfer(6783):   at com.squareup.okhttp.internal.http.RawHeaders.fromBytes(RawHeaders.java:301)
07-25 08:59:11.980: E/FileTransfer(6783):   at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:130)
07-25 08:59:11.980: E/FileTransfer(6783):   at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:630)
07-25 08:59:11.980: E/FileTransfer(6783):   at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:385)
07-25 08:59:11.980: E/FileTransfer(6783):   at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:334)
07-25 08:59:11.980: E/FileTransfer(6783):   at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:534)
07-25 08:59:11.980: E/FileTransfer(6783):   at org.apache.cordova.core.FileTransfer$3.run(FileTransfer.java:443)
07-25 08:59:11.980: E/FileTransfer(6783):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-25 08:59:11.980: E/FileTransfer(6783):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-25 08:59:11.980: E/FileTransfer(6783):   at java.lang.Thread.run(Thread.java:856)
07-25 08:59:11.980: E/FileTransfer(6783): Failed after uploading 25260 of 25260 bytes.

但奇怪的是,第一次上传工作正常,第二次失败,错误code 3的第三部作品,第四 - >错误...

The strange thing is, that the first upload works fine, the second fails with error code 3. The third works, the fourth -> error...

推荐答案

好吧,我刚刚度过的最后一天,或通过相同的问题,所以工作。什么工作对我来说是设置页眉关闭连接。

Okay, I just spent the last day or so working through the same issue. What worked for me was to set the header to close the connection.

options.headers = {连线:关};

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

上发现科尔多瓦Bug跟踪网站这样的回答: <一href="https://issues.apache.org/jira/browse/CB-2293?focusedCommentId=13696238&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13696238" rel="nofollow">https://issues.apache.org/jira/browse/CB-2293?focusedCommentId=13696238&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13696238

Found this answer on the cordova Bug Tracker site: https://issues.apache.org/jira/browse/CB-2293?focusedCommentId=13696238&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13696238

希望帮助,我知道我是多么沮丧与这一个了!

Hope that helps, I know how frustrated I was with this one too!

这篇关于PhoneGap的图片上传的作品只有一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆