Using Retrofit 2.4.0, I am making a @Multipart @POST request. I am sending a file as @Part along with some metadata as@PartMap. This is what the call looks like.
@Multipart
@POST("https://8hoot.com/my-path")
Single<Response<UploadMediaResponseModel>> uploadMedia(
@PartMap Map<String, RequestBody> metadata,
@Part MultipartBody.Part filePart
);
There is another Map<String, String>, let us call it subMetaMap, which contains related key-value pairs.
How can I store this subMetaMap in the @PartMap metadata? Something like shown below.
RequestBody subMetaMapAsRequestBody; // Convert subMetaMap to RequestBody
metadata.put("subMeta", subMetaMapAsRequestBody);
Currently, I am using the following method.
for (String s : subMetaMap.keySet()) {
RequestBody requestBody = RequestBody.create(MultipartBody.FORM, subMetaMap.get(s));
metadata.put(s, requestBody);
}
This is not the desired solution as I want the whole subMetaMap as the RequestBody not its individual key-value pairs
Edit 1- The backend team doesn't take different MIME types during Multipart request. So sending JSON, MessagePack, etc. is not an option.