0

The requirement is to upload max 40 images to the server, currently i am able to upload all the 40 images(with some data specific to that image)on to the server. Now I have to upload all the 40 Images in parallel(previously done sequentially).

for(int i=0;i<imageList.size();i++){
    MyAsync async = new MyAsync(imageList.get(i));
    async.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

The above code is the demo for what I did in my project. ImageList is the list of images which is I am passing to the AsyncTask to upload that Image.

Now at a time there is 9 parallel doInBackground() is called(added log to see).

when upload starts in doInBackground() method, I am using call.execute() to upload on Current Thread instead of call.enqueue().

The problem is, if there are 40 images to upload then only 5 to 6 images is uploading, I am uploading the original image with Multipart, so there is no wrong in uploading, infact sequential uploading is working fine.

The only problem is when trying to upload parallel way.

Can anybody please give me some suggestion to solve this kind of issue???

Any help is Appreciated.

Thanks in advance.

Mohd Asif Ahmed
  • 1,880
  • 2
  • 15
  • 29

2 Answers2

0

You can upload as many images as you want in sequential but when you use parallel Asyntasks , there is a limit for execution in parallel. Have a look at this link : https://stackoverflow.com/a/9654445/3303075 So it is preferred to go with the sequential upload rather worrying about cancellation of the task.

Community
  • 1
  • 1
Nilay Dani
  • 896
  • 6
  • 24
  • the purpose of parallel uploads here is to reduce the time of uploading. it is taken more than 10 min to uploads 40 images of 4-5 mb images. – Mohd Asif Ahmed Dec 22 '16 at 13:00
0

It depends on your network service provider, well the other way is to pass multiple files to Retrofit like this

public interface FileUploadService {  
    // previous code for single file uploads
    @Multipart
    @POST("upload")
    Call<ResponseBody> uploadFile(
            @Part("description") RequestBody description,
            @Part MultipartBody.Part file);

    // new code for multiple files
    @Multipart
    @POST("upload")
    Call<ResponseBody> uploadMultipleFiles(
            @Part("description") RequestBody description,
            @Part MultipartBody.Part file1,
            @Part MultipartBody.Part file2);
}

Try it maybe it can process faster.

Nilay Dani
  • 896
  • 6
  • 24