I am getting an IO Exception while trying to upload image to server using retrofit 2.0.2 and okhttp 3.2.0
at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:199 at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:125) at okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:723) at okhttp3.internal.http.HttpEngine.access$200(HttpEngine.java:81) at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:708) at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:563) at okhttp3.RealCall.getResponse(RealCall.java:241) at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198) at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203) at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187) at com.palaverplace.palaverplace.controller.api.RetrofitBase$1.intercept(RetrofitBase.java:74) at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:187) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
at okhttp3.RealCall.access$100(RealCall.java:30)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.io.EOFException: \n not found: size=0 content=...
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:201)
at okhttp3.internal.http.Http1xStream.readResponse
I used
@Multipart
@PUT("/common/imageUpload")
Call<Base> updateProfPic(@QueryMap HashMap<String,String> requestBody, @Part("image_file") RequestBody file);
And in the request class
MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
File file = new File(filePath);
RequestBody requestBody = RequestBody.create(MEDIA_TYPE_PNG, file);
HashMap<String,String> map = new HashMap<>();
map.put("key1",value1);
map.put("key2",value2);
map.put("key3",value3);
Call<Base> call = RetrofitBase.getRetrofitInstance(token).updatePic(map,requestBody);
What may be the issue