Multiplayer Image in an object of type class.
case 1. (What I did)
Service Parameters:
{"id":"1","name":"vishal","image/file":""}
At this time, my API of Retrofit
@Multipart @POST("webservice") Call<SignUpResp> loadSignupMultipart(@Part("description") RequestBody description, @Part MultipartBody.Part file, @QueryMap HashMap<String, String> params);
case 2. (where I have a problem) with @Body class<UploadwithImage>
{ "methodName":"submitLevel1Part2Icon", "userid":"150", "headerData":{ "fiction":{ "icon_type":"1", "icon_id":"3"}, "nonfiction":{ "icon_type":"2", "icon_id":"4"}, "relation":{ "icon_type":"3", "icon_id":"0", "name":"Ronak", "relative_image":"<File>", "relation_id":"3"}, "self":{ "icon_type":"4", "icon_id":"0"} } }
I'm trying to make this API
@Multipart @POST("webservice") Call<SubmitLevel1Part2IconResp> loadLevel1halfIconswithImage(@Part("description") RequestBody description, @Part MultipartBody.Part file, @Body UploadwithImage uploadImage);
Java side
/** * code for multipart */ // create RequestBody instance from file RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), fileUpload); // MultipartBody.Part is used to send also the actual filename MultipartBody.Part body = MultipartBody.Part.createFormData("methodName[headerData][relation][relative_image]", fileUpload.getName(), requestFile); // add another part within the multipart request String descriptionString = "hello, this is description speaking"; RequestBody description = RequestBody.create(MediaType.parse("multipart/form-data"), descriptionString); call = service.loadLevel1halfIconswithImage(description, body, levelOneHalfIcons);
I do not know why, but it returns an error, for example:
"@ Body parameters cannot be used with form or multi-part encoding"
Any help would be appreciated.