@Part parameters can only be used with multipart encoding. (parameter #8)

R Besar picture R Besar · Aug 29, 2016 · Viewed 20.5k times · Source

Before I post this question here, I have tried to add @Multipart above interface method And searching in stackoverflow still cannot find similar with my problem.

In this case, I try to send image using TypedFile to server. My interface method look like this :

 @Headers({"Content-type: application/json"})
    @POST("/user/change")
    void postChange(@Query("name") String name, @Query("email") String  email, @Query("password") String password, @Query("phone") String phone, @Query("user_id") String userId, @Query("address[]") String[] listAddress, @Query("head[]") String[] head, @Part("photo_profile") TypedFile photoProfile, @Body TypedInput jsonObject, Callback<ReceiveDTO> callback);

EDIT

In that method we can see @Part and @Body. If i add @Multipart above the method, it will we throw an error @Body parameters cannot be used with form or multi-part encoding. (parameter #9)

I am using Retrofit 1.9

Answer

Miguel Rdz picture Miguel Rdz · Nov 7, 2018

For anyone with the same issue, make sure to add the @Multipart annotation above your @POST/@PUT. I had the same error and my problem was just that I was missing that @Multipart annotation.