Following API I called for Editing User Profile . I have to send user profile picture so I used multipart in API .
@Multipart
@POST(ApiURLs.EDIT_USER_PROFILE)
Call<EditProfileModel> EditUserProfile (@Part("user_id) String userId ,
@Part("user_name") String userName ,
@Part("language_id") String languageId ,
@Part("state_id") String stateId ,
@Part MultipartBody.Part
profilePicture);
When Service called the requested parameters would be like
"user_id" : ""23"" "user_name" : ""Keval Shukla"" "language_id": ""27"" "state_id" : "53""
how do i remove that double quote using MultiPart ?
It must be like -
@Multipart
@POST(ApiURLs.EDIT_USER_PROFILE)
Call<EditProfileModel> EditUserProfile (
@Part("user_id") RequestBody userId ,
@Part("user_name") RequestBody userName ,
@Part("language_id") RequestBody languageId ,
@Part("state_id") RequestBody stateId ,
@Part RequestBody profilePicture);
And, to create requestBody,
File file = new File(imageURI.getPath());
RequestBody fbody = RequestBody.create(MediaType.parse("image/*"), file); // File requestBody
RequestBody userName = RequestBody.create(MediaType.parse("text/plain"), userNameSTRING); // String requestBody
You can send parameters other than file as RequestBody
.
@Multipart
@POST(ApiURLs.EDIT_USER_PROFILE)
Call<EditProfileModel> EditUserProfile (@Part("user_id) RequestBody userId ,
@Part("user_name") RequestBody userName ,
@Part("language_id") RequestBody languageId ,
@Part("state_id") RequestBody stateId ,
@Part MultipartBody.Part profilePicture);
To Convert String
to RequestBody
:
RequestBody requestBody = RequestBody.create(MediaType.parse("text/plain"), userName); // Here userName is String
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With