1

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

John Shelley
  • 2,655
  • 3
  • 27
  • 36

1 Answers1

5

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.

bsberry
  • 954
  • 1
  • 10
  • 24
  • Well that did the trick, no more socket timeout issue. But I am running into other items right now. I'll give it a look and if it doesn't relate to this question I'll mark your answer as correct. – John Shelley Apr 29 '14 at 02:51
  • Quick question @Hober, I've seen some people set their Retrofit RestAdatper to use an OkHttpClient and other say you just need the library added to make it work. Any suggestions there? – John Shelley Apr 29 '14 at 02:52
  • @JohnShelley according to source code of Retrofit it uses OkHttpClient by default if it is present on the classpath. – GregoryK Oct 21 '15 at 10:42
  • it doesn't work in my case.. still getting samejava.net.SocketTimeoutException: timeout – Pihu Jul 12 '16 at 06:31