2

This might seem similar to earlier questions but none actually answers my question. I need to Post multiple fields and multiple images in one request using retrofit2 and i'm getting this error

java.lang.IllegalArgumentException: Only one encoding annotation is allowed.for method xxx

i'm using

@Multipart
@FormUrlEncoded

since @Field requires @FormUrlEncoded and @Part requires @Multipart. the more logical thing to do is to remove the @FormUrlEncoded annotation, but how do i go from there. Now the question is how do i go about the task to achieve sending my post in a single request.

here's the interface

@Multipart
@FormUrlEncoded
@POST("upload")
Call<ResponseBody> uploadPost(@FieldMap Map<String, String> map,
                       @Part MultipartBody.Part image1,
                       @Part MultipartBody.Part image2,
                       @Part MultipartBody.Part image3);

1 Answers1

3
@Multipart
@POST("upload")
Call<ResponseBody> uploadPost(
        @PartMap() Map<String, RequestBody> descriptions,
        @Part List<MultipartBody.Part> images);

use this interface.

Sumit Saxena
  • 1,152
  • 9
  • 7
  • Why there is RequestBody in Map can't we use String in it – Herry Dec 30 '16 at 08:02
  • Yes you can use it. But for that you have to use string converter Have a look at this post [link](http://stackoverflow.com/questions/35520012/get-string-response-body-from-retrofit2) – Sumit Saxena Dec 31 '16 at 09:14