我正在按照以下示例通过 PHP 服务器从 phonegap 上传图像。
不良行为是它有时有效,有时无效。这是相同图像和不同图像的情况。一次尝试失败(返回代码 3)并再次尝试相同的图像似乎有效。
我希望能够第一次上传而无需一直对所有图像再次尝试,而不是仅在某些时候。
到目前为止发现的现有解决方案涉及访问源和 chunkMode,但仍然没有成功。
您的帮助将不胜感激。
我正在使用一个看起来很健壮的 USB 桥接器,并将 XAMPP 作为我的 PHP 运行的服务器。我还确保所有最大限制都足够多(例如upload_max_filesize = 64M)。图片小于2M。已重新启动服务器并将其关闭并重新启动,但仍然没有结果。
下面是 LogCat 的输出。
06-20 22:46:05.268: D/DroidGap(29662): Resuming the App
06-20 22:46:07.430: D/FileTransfer(29662): upload content://media/external/images/media/4610 to http://127.0.0.1:8092/upload_server/imageUpload.php
06-20 22:46:07.430: D/FileTransfer(29662): fileKey: file
06-20 22:46:07.440: D/FileTransfer(29662): fileName: 4610
06-20 22:46:07.440: D/FileTransfer(29662): mimeType: image/jpeg
06-20 22:46:07.440: D/FileTransfer(29662): params: {}
06-20 22:46:07.440: D/FileTransfer(29662): trustEveryone: true
06-20 22:46:07.440: D/FileTransfer(29662): chunkedMode: false
06-20 22:46:07.440: D/FileTransfer(29662): headers: null
06-20 22:46:07.440: D/FileTransfer(29662): objectId: 4
06-20 22:46:07.440: D/FileTransfer(29662): httpMethod: POST
06-20 22:46:07.480: D/FileTransfer(29662): Content Length: 1201787
06-20 22:46:07.490: W/FileTransfer(29662): Error getting HTTP status code from connection.
06-20 22:46:07.490: W/FileTransfer(29662): java.io.EOFException
06-20 22:46:07.490: W/FileTransfer(29662): at libcore.io.Streams.readAsciiLine(Streams.java:203)
06-20 22:46:07.490: W/FileTransfer(29662): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:560)
06-20 22:46:07.490: W/FileTransfer(29662): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:813)
06-20 22:46:07.490: W/FileTransfer(29662): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
06-20 22:46:07.490: W/FileTransfer(29662): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
06-20 22:46:07.490: W/FileTransfer(29662): at org.apache.cordova.FileTransfer.createFileTransferError(FileTransfer.java:626)
06-20 22:46:07.490: W/FileTransfer(29662): at org.apache.cordova.FileTransfer.access$600(FileTransfer.java:67)
06-20 22:46:07.490: W/FileTransfer(29662): at org.apache.cordova.FileTransfer$1.run(FileTransfer.java:523)
06-20 22:46:07.490: W/FileTransfer(29662): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-20 22:46:07.490: W/FileTransfer(29662): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-20 22:46:07.490: W/FileTransfer(29662): at java.lang.Thread.run(Thread.java:856)
06-20 22:46:07.500: E/FileTransfer(29662): {"target":"http:\/\/127.0.0.1:8092\/upload_server\/imageUpload.php","source":"content:\/\/media\/external\/images\/media\/4610","http_status":0,"code":3}
06-20 22:46:07.500: E/FileTransfer(29662): java.net.SocketException: sendto failed: EPIPE (Broken pipe)
06-20 22:46:07.500: E/FileTransfer(29662): at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:517)
06-20 22:46:07.500: E/FileTransfer(29662): at libcore.io.IoBridge.sendto(IoBridge.java:486)
06-20 22:46:07.500: E/FileTransfer(29662): at java.net.PlainSocketImpl.write(PlainSocketImpl.java:508)
06-20 22:46:07.500: E/FileTransfer(29662): at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
06-20 22:46:07.500: E/FileTransfer(29662): at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:270)
06-20 22:46:07.500: E/FileTransfer(29662): at libcore.net.http.FixedLengthOutputStream.write(FixedLengthOutputStream.java:41)
06-20 22:46:07.500: E/FileTransfer(29662): at java.io.OutputStream.write(OutputStream.java:82)
06-20 22:46:07.500: E/FileTransfer(29662): at org.apache.cordova.FileTransfer$1.run(FileTransfer.java:440)
06-20 22:46:07.500: E/FileTransfer(29662): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-20 22:46:07.500: E/FileTransfer(29662): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-20 22:46:07.500: E/FileTransfer(29662): at java.lang.Thread.run(Thread.java:856)
06-20 22:46:07.500: E/FileTransfer(29662): Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe)
06-20 22:46:07.500: E/FileTransfer(29662): at libcore.io.Posix.sendtoBytes(Native Method)
06-20 22:46:07.500: E/FileTransfer(29662): at libcore.io.Posix.sendto(Posix.java:146)
06-20 22:46:07.500: E/FileTransfer(29662): at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
06-20 22:46:07.500: E/FileTransfer(29662): at libcore.io.IoBridge.sendto(IoBridge.java:484)
06-20 22:46:07.500: E/FileTransfer(29662): ... 9 more
06-20 22:46:07.500: E/FileTransfer(29662): Failed after uploading 0 of 1201787 bytes.