2012-09-28 76 views
7

我有一個針對android的cordova 2.0應用程序。我使用FileTransfer Plugin將一些數據加載到我的服務器。第一次,上傳被執行,一切正常。但後來我得到了EPIPE(Broken Pipe)錯誤。如果我只是再次推上傳按鈕,它就可以工作。EPIPE(Broken Pipe)使用FileTransfer-plugin與cordova 2.0時出現的問題

如何防止錯誤?

09-28 17:31:12.304: W/FileTransfer(29497): Error getting HTTP status code from connection. 
09-28 17:31:12.304: W/FileTransfer(29497): java.net.SocketException: sendto failed: EPIPE (Broken pipe) 
09-28 17:31:12.304: W/FileTransfer(29497): at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:506) 
09-28 17:31:12.304: W/FileTransfer(29497): at libcore.io.IoBridge.sendto(IoBridge.java:475) 
09-28 17:31:12.304: W/FileTransfer(29497): at java.net.PlainSocketImpl.write(PlainSocketImpl.java:507) 
09-28 17:31:12.304: W/FileTransfer(29497): at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46) 
09-28 17:31:12.304: W/FileTransfer(29497): at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269) 
09-28 17:31:12.304: W/FileTransfer(29497): at libcore.net.http.ChunkedOutputStream.writeHex(ChunkedOutputStream.java:102) 
09-28 17:31:12.304: W/FileTransfer(29497): at libcore.net.http.ChunkedOutputStream.writeBufferedChunkToSocket(ChunkedOutputStream.java:128) 
09-28 17:31:12.304: W/FileTransfer(29497): at libcore.net.http.ChunkedOutputStream.close(ChunkedOutputStream.java:118) 
09-28 17:31:12.304: W/FileTransfer(29497): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:804) 
09-28 17:31:12.304: W/FileTransfer(29497): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274) 
09-28 17:31:12.304: W/FileTransfer(29497): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486) 
09-28 17:31:12.304: W/FileTransfer(29497): at org.apache.cordova.FileTransfer.createFileTransferError(FileTransfer.java:384) 
09-28 17:31:12.304: W/FileTransfer(29497): at org.apache.cordova.FileTransfer.upload(FileTransfer.java:316) 
09-28 17:31:12.304: W/FileTransfer(29497): at org.apache.cordova.FileTransfer.execute(FileTransfer.java:85) 
09-28 17:31:12.304: W/FileTransfer(29497): at org.apache.cordova.api.PluginManager$1.run(PluginManager.java:192) 
09-28 17:31:12.304: W/FileTransfer(29497): at java.lang.Thread.run(Thread.java:856) 
09-28 17:31:12.304: W/FileTransfer(29497): Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe) 
09-28 17:31:12.304: W/FileTransfer(29497): at libcore.io.Posix.sendtoBytes(Native Method) 
09-28 17:31:12.304: W/FileTransfer(29497): at libcore.io.Posix.sendto(Posix.java:146) 
09-28 17:31:12.304: W/FileTransfer(29497): at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177) 
09-28 17:31:12.304: W/FileTransfer(29497): at libcore.io.IoBridge.sendto(IoBridge.java:473) 
09-28 17:31:12.304: W/FileTransfer(29497): ... 14 more 
09-28 17:31:12.319: E/FileTransfer(29497): {"target":"http:\/\/10.100.150.173:8081\/mobile110\/upload","source":"content:\/\/media\/external\/images\/media\/30","code":3} 
09-28 17:31:12.319: E/FileTransfer(29497): java.net.SocketException: sendto failed: EPIPE (Broken pipe) 
09-28 17:31:12.319: E/FileTransfer(29497): at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:506) 
09-28 17:31:12.319: E/FileTransfer(29497): at libcore.io.IoBridge.sendto(IoBridge.java:475) 
09-28 17:31:12.319: E/FileTransfer(29497): at java.net.PlainSocketImpl.write(PlainSocketImpl.java:507) 
09-28 17:31:12.319: E/FileTransfer(29497): at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46) 
09-28 17:31:12.319: E/FileTransfer(29497): at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269) 
09-28 17:31:12.319: E/FileTransfer(29497): at libcore.net.http.ChunkedOutputStream.writeHex(ChunkedOutputStream.java:102) 
09-28 17:31:12.319: E/FileTransfer(29497): at libcore.net.http.ChunkedOutputStream.writeBufferedChunkToSocket(ChunkedOutputStream.java:128) 
09-28 17:31:12.319: E/FileTransfer(29497): at libcore.net.http.ChunkedOutputStream.write(ChunkedOutputStream.java:77) 
09-28 17:31:12.319: E/FileTransfer(29497): at java.io.DataOutputStream.write(DataOutputStream.java:98) 
09-28 17:31:12.319: E/FileTransfer(29497): at org.apache.cordova.FileTransfer.upload(FileTransfer.java:261) 
09-28 17:31:12.319: E/FileTransfer(29497): at org.apache.cordova.FileTransfer.execute(FileTransfer.java:85) 
09-28 17:31:12.319: E/FileTransfer(29497): at org.apache.cordova.api.PluginManager$1.run(PluginManager.java:192) 
09-28 17:31:12.319: E/FileTransfer(29497): at java.lang.Thread.run(Thread.java:856) 
09-28 17:31:12.319: E/FileTransfer(29497): Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe) 
09-28 17:31:12.319: E/FileTransfer(29497): at libcore.io.Posix.sendtoBytes(Native Method) 
09-28 17:31:12.319: E/FileTransfer(29497): at libcore.io.Posix.sendto(Posix.java:146) 
09-28 17:31:12.319: E/FileTransfer(29497): at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177) 
09-28 17:31:12.319: E/FileTransfer(29497): at libcore.io.IoBridge.sendto(IoBridge.java:473) 
09-28 17:31:12.319: E/FileTransfer(29497): ... 11 more 
+0

你找到一個解決方案這個呢? – varevarao

+0

不是,我剛剛提交了該文件。 –

+0

Ah darn。這個問題是一個真正的失敗者,幾乎沒有任何幫助,幾乎沒有任何東西來理解原因。 – varevarao

回答

7

我也一直在努力解決隨機間歇性HTTP狀態錯誤,並使用VAR來存儲重試狀態都採用一種變通方法。然後我增加此變種如果傳輸失敗,調用回調函數,然後重試上傳功能最多3次(雖然它不是必需的超過1重試):

var imageRetry = 0; // if upload errors, retry 3 times 
... 
// file transfer fail callback 
function fail(error) { 
    if(imageRetry < 3){ 
     imageRetry++; 
     uploadPhoto(); // call upload function again 
    }else{ 
     // normal failure handling 
    } 
} 

注:服務器白名單,我已經嘗試禁用chunkedMode以及沒有成功。我也沒有使用普通或自簽名的SSL。就我而言,用戶可以在上傳之前過濾照片。如果沒有應用過濾器,上傳總是成功。如果用戶試圖將任何過濾器,上傳隨機失敗,錯誤代碼3

(是的,我知道這個解決方案並不完全理想,但它比未恢復的失敗要好。)

+0

我這樣做,但我真的不喜歡這個workarround。 –

+0

看起來沒有選擇,我必須部署相同的方法 – DdD

+0

它可能會在3.4.0中修復:https://issues.apache.org/jira/browse/CB-2293 – user276648

相關問題