My requirement is to pass the request in the below format,
I don't have any idea on how to send request in the below format using a @PartMap,
{
"image", img1.jpg,
"image", img2.jpg,
"service_request", "asd123123asfsf"
}
The type for above format,
{
"<String>", <Image file>,
"<String>", <Image file>,
"<String>", "<String>"
}
My current method
private void uploadMultipleFiles() {
SharedPreferences preferences = getApplicationContext().getSharedPreferences("MY_APP", Context.MODE_PRIVATE);
String retrivedToken = "Token " + preferences.getString("TOKEN", null);
String attachment_one = preferences.getString("Attachement_one", null);
String attachement_two = preferences.getString("Attachement_two", null);
File file_one = new File(attachment_one);
File file_two = new File(attachement_two);
RequestBody requestBody1 = RequestBody.create(MediaType.parse("*/*"), file_one);
RequestBody requestBody2 = RequestBody.create(MediaType.parse("*/*"), file_two);
MultipartBody.Part fileToUpload1 = MultipartBody.Part.createFormData("file1", file_one.getName(), requestBody1);
MultipartBody.Part fileToUpload2 = MultipartBody.Part.createFormData("file2", file_two.getName(), requestBody2);
Call<ResponseBody> call = ServiceBuilder.getInstance().getApi().uploadImages(retrivedToken, "multipart/form-data", fileToUpload1, fileToUpload2, filename);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (!response.isSuccessful()) {
System.out.println("Response Code: " + response.code());
return;
} else {
System.out.println("Response Code: " + response.code());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
System.out.println("Message: " + t.getMessage());
}
});
}
Service method
@Multipart
@POST("http://192.168.1.100:8000/yrtp/service/request/upload")
Call <ResponseBody> uploadImages(@Header ("Authorization") String token, @Header("Content-Type") String type, @Part MultipartBody.Part file1, @Part MultipartBody.Part file2, @Part("service_request") RequestBody description);
I'm new in using the @PartMap in retrofit and android. Kindly help me with a solution. Million thanks in advance!