I want to upload three images using retrofit along with other text fields.How can I upload this and how can call the web service using retrofit?
Asked
Active
Viewed 2,068 times
0
-
Check this :https://futurestud.io/tutorials/retrofit-2-how-to-upload-a-dynamic-amount-of-files-to-server – Kabir Aug 13 '19 at 06:20
-
can you please specify the type of webservice endpoint you are using. Whether it accepts only one file or multiple files.This can help you to get specific answer. :) – Monster Brain Aug 13 '19 at 06:57
-
I am using retrofit. – Devika Reji Aug 13 '19 at 07:04
-
Have you checked [this](https://stackoverflow.com/questions/39866676/retrofit-uploading-multiple-images-to-a-single-key)? – Piyush Aug 13 '19 at 07:06
-
Api Service Interface: @Multipart @POST("Edit_profile") Call
EditProfile(@Part("USERID") String userid, @Part("IMAGEONE\"; filename=\"myfile.jpg\" ") RequestBody imageone, @Part("IMAGETWO\"; filename=\"myfile.jpg\" ") RequestBody imagetwo, @Part("IMAGETHREE\"; filename=\"myfile.jpg\" ") RequestBody imagethree); – Devika Reji Aug 13 '19 at 09:58 -
File fileone = new File(getfileonepath(fileoneUri)); RequestBody requestFileone = RequestBody.create(MediaType.parse(getContentResolver().getType(fileoneUri)), fileone); – Devika Reji Aug 13 '19 at 10:00
-
ApiServiceInterface apiServiceInteface=ApiClient.getClient().create(ApiServiceIterface.class); Call
usercall=apiServiceInteface.EditProfile(userid,requestFileone,requestFiletwo,requestFilethree); – Devika Reji Aug 13 '19 at 10:00 -
This is my code – Devika Reji Aug 13 '19 at 10:01
2 Answers
0
You should take a look on @Multipart & @Part annotations documentation They allow you to create a method like
@Multipart
@POST("/")
Call<ResponseBody> example(
@Part("description") String description,
@Part(value = "image", encoding = "8-bit") RequestBody image);
Which should do the thing for you.

BAZTED
- 546
- 5
- 16
0
public interface UploadImages {
@Multipart
@POST("upload_images")
Call<ResponseBody> uploadMultipleFiles(
@Part("text") RequestBody text,
@Part List<MultipartBody.Part> images);
}
OR
@Multipart
@POST("upload_images")
Call<ResponseBody> uploadMultipleFiles(@Part("text") RequestBody text,
@Part MultipartBody.Part file1,
@Part MultipartBody.Part file2,
@Part MultipartBody.Part file3);

Bhushan
- 424
- 5
- 15