I want to send Image as form-data and userId as Params in retrofit android.enter image description hereI have tried many solution but did not got any success. here is my code and api.
@Multipart @POST("upload/profile") fun uploadProfilePhoto(@Part image: MultipartBody.Part, @Query("userId") userId: String): Call
val photoContent = RequestBody.create(MediaType.parse("image/*"), file)
val photo = MultipartBody.Part.createFormData("image", file.name, photoContent)
I got the error in my case. actually when we post multipart parameter then we have to match our formData name with backend in the API. in my case it was "image/png" val photo = MultipartBody.Part.createFormData("image", file.name, photoContent)