我的應用需要將照片上傳到服務器。這在上傳第一張照片時效果很好。當我拍攝另一張照片時,上傳失敗。Phonegap圖片上傳僅適用一次
這裏是我的代碼:
// 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的
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.
奇怪的是,第一次上傳工作正常,第二個失敗,錯誤代碼得到這個錯誤3.第三作品,第四 - >錯誤...
參考答案,這問題[** here **](http://stackoverflow.com/questions/17723522/opening-camera-instance-from-a-web-app/17724235#17724235) –
是的,我試過這麼多!這是來自PG文檔的代碼。仍然是同樣的問題。第一次上傳勝利,第二次失敗。奇怪的是,第三,第五,第七...上傳的作品,但不是第二,第四,第六...... – m1crdy