Retrofit SocketTimeoutException - Uploading Image

蹲街弑〆低调 提交于 2019-12-13 17:54:07

问题


I'm currently using Retrofit for Android as my network communications. When POSTing to my backend server an image, the server is in the middle of the upload and then retrofit "times out" with SocketTimeoutException.

I have added the OKhttp library as some have suggested and still getting the timeout.

The current img sizes are around 750kb because I have scaled them down.

Is there an appropriate way to changes the amount of time until a timeout for retrofit? Or is there a better way to upload images to a server?

Thanks


回答1:


Perhaps try changing the timeout with setReadTimeout on your OkHttpClient; note that a setting of 0 indicates to never time out.

Bonus: if you need help figuring out an appropriate setting, you can read the bytes successfully transferred before the timeout from the exception, and also find out the current default read timeout with getReadTimeout.



来源:https://stackoverflow.com/questions/23347898/retrofit-sockettimeoutexception-uploading-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!