EPIPE(Broken Pipe)在使用FileTransfer-plugin和cordova 2.0时出现Bug

我有一个androidcordova 2.0应用程序。 我使用FileTransfer插件来将一些数据加载到我的服务器。 第一次,上传被执行,一切工作正常。 但是,然后我得到一个EPIPE(断pipe)错误。 如果我只是再次推上传button,它的工作。

我怎样才能防止错误?

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 

Solutions Collecting From Web of "EPIPE(Broken Pipe)在使用FileTransfer-plugin和cordova 2.0时出现Bug"

我也一直在处理随机的间歇性的HTTP状态错误,并采用了一个解决方法,使用var来存储重试状态。 然后,如果传输失败callback被调用,然后重试上传function最多3次(虽然它不需要超过1次重试),然后增加此var:

 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。 就我而言,用户可以在上传之前过滤照片。 如果没有应用filter,上传总是成功。 如果用户尝试应用任何filter,则随机上传失败,错误代码为3。

(是的,我知道这个解决scheme并不是完全理想的,但是它比未被发现的失败要好。)