0

Hi Can any one Please help me out in uploading multiple images selected from gallery, parameter is 'images' as array list I have tried with this but no response can any one help me out..

This is my request body :

  MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
    MultipartBody.Builder mRequestBody = new MultipartBody.Builder()
            .setType(MultipartBody.FORM);
    if (Imagepaths.size() > 0) {
        for(String path:Imagepaths) {
            File file = new File(path);
            mediaType = path.endsWith("png") ?
                    MediaType.parse("image/png") : MediaType.parse("image/jpeg");
            RequestBody imageBody = RequestBody.create(mediaType, file);
            mRequestBody.addFormDataPart("images", file.getName(), imageBody);
        }
    }

    RequestBody rb = mRequestBody.build();

This is the retrofit call :

 @Multipart
@POST("upload_images/")
Call<ResponseBody> retrofitImageUpload(@Header("Authorization") String auth,
                                       @Header("Content-Type") String contentType,
                                       @Part("images") RequestBody req);
Rahul
  • 99
  • 6
  • Show your code. – Piyush Nov 20 '18 at 08:21
  • https://medium.com/@adinugroho/upload-image-from-android-app-using-retrofit-2-ae6f922b184c – Brian Hoang Nov 20 '18 at 08:22
  • Check [this](https://stackoverflow.com/questions/34395873/android-okhttp-addformdatapart-dynamically-for-multiple-image/34411666#34411666) – Piyush Nov 20 '18 at 08:23
  • try using https://stackoverflow.com/questions/39866676/retrofit-uploading-multiple-images-to-a-single-key – ahuja007 Nov 20 '18 at 08:28
  • ImagePaths is the uri array list i get from selected image eg: /storage/emulated/0/DCIM/Screenshots/Screenshot_20180928-19451.jpg – Rahul Nov 20 '18 at 08:32
  • @ahuja007 Can you help? https://stackoverflow.com/questions/62783444/why-does-multipart-pdf-is-not-able-to-upload-in-api-using-retrofit-2-in-android?noredirect=1#comment111031344_62783444 – Priyanka Singh Jul 08 '20 at 07:40

0 Answers0