Peterstev Uremgba
Peterstev Uremgba

Reputation: 729

Using @FieldMap and @Part in single request in Retrofit2 gets java.lang.IllegalArgumentException: Only one encoding annotation is allowed.for method

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);

Upvotes: 2

Views: 3548

Answers (1)

Sumit Saxena
Sumit Saxena

Reputation: 1187

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

use this interface.

Upvotes: 3

Related Questions