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

左心房为你撑大大i 提交于 2019-12-01 09:03:00

问题


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:


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

use this interface.



来源:https://stackoverflow.com/questions/39820762/using-fieldmap-and-part-in-single-request-in-retrofit2-gets-java-lang-illegala

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