2015-09-10 21 views
0

即時通訊使用okhttp 2.5.0, 即時通訊照片,然後將其轉換爲基本64格式,然後將其發送到服務器作爲後變量,然後解碼回jpg格式並保存到到服務器.... 當我使用小相似圖片1個百萬像素(0.5MB),它完美... 但是當我將分辨率提高會發生此異常...試圖上傳圖像,但得到這個錯誤Android應用程序

09-10 23:29:47.673 25742-27156/in.definexit.chemapp W/System.err﹕ java.net.SocketTimeoutException: timeout 
09-10 23:29:47.676 25742-27156/in.definexit.chemapp W/System.err﹕ at okio.Okio$3.newTimeoutException(Okio.java:207) 
09-10 23:29:47.676 25742-27156/in.definexit.chemapp W/System.err﹕ at okio.AsyncTimeout.exit(AsyncTimeout.java:261) 
09-10 23:29:47.677 25742-27156/in.definexit.chemapp W/System.err﹕ at okio.AsyncTimeout$1.write(AsyncTimeout.java:158) 
09-10 23:29:47.677 25742-27156/in.definexit.chemapp W/System.err﹕ at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176) 
09-10 23:29:47.677 25742-27156/in.definexit.chemapp W/System.err﹕ at okio.RealBufferedSink.write(RealBufferedSink.java:46) 
09-10 23:29:47.677 25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.internal.http.HttpConnection$FixedLengthSink.write(HttpConnection.java:302) 
09-10 23:29:47.677 25742-27156/in.definexit.chemapp W/System.err﹕ at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176) 
09-10 23:29:47.677 25742-27156/in.definexit.chemapp W/System.err﹕ at okio.RealBufferedSink.write(RealBufferedSink.java:96) 
09-10 23:29:47.679 25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.RequestBody$2.writeTo(RequestBody.java:96) 
09-10 23:29:47.679 25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.MultipartBuilder$MultipartRequestBody.writeOrCountBytes(MultipartBuilder.java:277) 
09-10 23:29:47.682 25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.MultipartBuilder$MultipartRequestBody.writeTo(MultipartBuilder.java:297) 
09-10 23:29:47.682 25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:887) 
09-10 23:29:47.682 25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:749) 
09-10 23:29:47.682 25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.Call.getResponse(Call.java:268) 
09-10 23:29:47.684 25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224) 
09-10 23:29:47.685 25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195) 
09-10 23:29:47.686 25742-27156/in.definexit.chemapp W/System.err﹕ at com.squareup.okhttp.Call.execute(Call.java:79) 
09-10 23:29:47.686 25742-27156/in.definexit.chemapp W/System.err﹕ at in.definexit.chemapp.BGServerScripts.doInBackground(BGServerScripts.java:112) 
09-10 23:29:47.686 25742-27156/in.definexit.chemapp W/System.err﹕ at in.definexit.chemapp.BGServerScripts.doInBackground(BGServerScripts.java:27) 
09-10 23:29:47.686 25742-27156/in.definexit.chemapp W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:292) 
09-10 23:29:47.686 25742-27156/in.definexit.chemapp W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
09-10 23:29:47.687 25742-27156/in.definexit.chemapp W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
09-10 23:29:47.687 25742-27156/in.definexit.chemapp W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
09-10 23:29:47.687 25742-27156/in.definexit.chemapp W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
09-10 23:29:47.687 25742-27156/in.definexit.chemapp W/System.err﹕ at java.lang.Thread.run(Thread.java:818) 
09-10 23:29:47.687 25742-27156/in.definexit.chemapp W/System.err﹕ Caused by: java.net.SocketException: Socket closed 
09-10 23:29:47.690 25742-27156/in.definexit.chemapp W/System.err﹕ at libcore.io.Posix.sendtoBytes(Native Method) 
09-10 23:29:47.690 25742-27156/in.definexit.chemapp W/System.err﹕ at libcore.io.Posix.sendto(Posix.java:206) 
09-10 23:29:47.690 25742-27156/in.definexit.chemapp W/System.err﹕ at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:278) 
09-10 23:29:47.691 25742-27156/in.definexit.chemapp W/System.err﹕ at libcore.io.IoBridge.sendto(IoBridge.java:513) 
09-10 23:29:47.691 25742-27156/in.definexit.chemapp W/System.err﹕ at java.net.PlainSocketImpl.write(PlainSocketImpl.java:504) 
09-10 23:29:47.691 25742-27156/in.definexit.chemapp W/System.err﹕ at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:37) 
09-10 23:29:47.691 25742-27156/in.definexit.chemapp W/System.err﹕ at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:266) 
09-10 23:29:47.691 25742-27156/in.definexit.chemapp W/System.err﹕ at okio.Okio$1.write(Okio.java:80) 
09-10 23:29:47.691 25742-27156/in.definexit.chemapp W/System.err﹕ at okio.AsyncTimeout$1.write(AsyncTimeout.java:155) 
09-10 23:29:47.692 25742-27156/in.definexit.chemapp W/System.err﹕ ... 22 more 

我試圖增加文章和上傳大小在php.ini中, 增加了asynctask和okhttp客戶端的時間, 沒有工作

+3

不介意了「跳過140幀」的事情 – RIPjoker

+0

你檢查所致套接字關閉? –

+0

你可以發佈你用來上傳圖片的代碼嗎? –

回答

0

這是拋SocketTimeoutException只是延長超時。

或者在上傳之前添加更多代碼來調整圖片的大小,無論如何您都希望有一個限制。

+0

你知道這很可疑,對吧? –

+0

@meda我不想減小圖像的大小...因爲它將是圖像的圖像質量的圖像是必不可少的...我試圖通過使用 'client.setConnectTimeout(15,TimeUnit。 SECONDS);' 但來自[鏈接](http://stackoverflow.com/questions/25953819/how-to-set-connection-timeout-with-okhttp),但它沒有幫助 – RIPjoker

+0

@meda [Scripts](https: //drive.google.com/folderview?id=0B1jzoj6y0Qb7TGdvSHlYZm5tQkE&usp=sharing)BGServerScript處理異步任務,CompleteTheOrderFragement運行bgServerScript上傳圖像,並且serverImageUpload是服務器腳本 – RIPjoker

0

您正在使用Base64發送圖像。 Base64基本上是一個二進制數據的ASCII表示,它允許我們將數據嵌入到JSON等文本流中,但也應該注意,使用它的數據的大小會增加。您正在接收SocketTimeoutException,因爲數據量很大,上傳呼叫在超時之前未完成,或者網絡速度較慢,並且圖像未在指定時間內上傳。

使用multipart/form-data是在HTTP請求中傳輸二進制文件的標準方式。除非這樣做有一些限制,否則使用這種方法總是更好。

+0

我使用okhttp api的multipart/form-data ... 可以請你給我一些想法來解決這個問題嗎? – RIPjoker

+0

如果你使用multipart/form-data,那麼Base64的必要性是什麼。它會增加正在發送的數據的大小。您是否能夠在不使用Base64編碼的情況下上傳圖像? –

0

我解決了增加writeTimeout的問題。 在okhttp3嘗試:java.net.SocketException異常:

OkHttpClient.Builder builder = new OkHttpClient(). 
builder.connectTimeout(5, TimeUnit.MINUTES); 
writeTimeout(5, TimeUnit.MINUTES); 
readTimeout(5, TimeUnit.MINUTES); 
okHttpClient = builder.build(); 
相關問題