wymsee / cordova-imagePicker

Cordova Plugin For Multiple Image Selection
MIT License
407 stars 853 forks source link

ImagePicker Loop Times out File Transfer that causes Code 3 Error #264

Closed Mr-Anonymous closed 6 years ago

Mr-Anonymous commented 6 years ago

I use Image Picker plugin and use File Transfer to upload the file. What I noticed is that, it seems to upload the first few images and the ones at the last end of the queue fails with a Code 3 error. The error is like this:

body: null
code: 3
exception: null
http_status: null
source: "file:///var/mobile/Containers/Data/Application/FDDESS-CC1D-439E-FEEW-8003Bddss69DF74B/tmp/cdv_photo_012.jpg"
target: "https://www.example.com/upload"

What I feel is, this error is probably due to the timeout in the File Transfer queue and it happens when users upload 15 files where the first 10-12 files uploads fine and the remaining ones throws this error.

Has anyone else experienced this when using ImagePicker with File Transfer plugin? How do you mitigate it?

              window.imagePicker.getPictures(
                function(results) {
                  for (var i = 0; i < results.length; i++) {
                    var fileURI = results[i];
                    if (fileURI) {
                        // use FileTransfer
                        var promise = fileTransfer(fileURI, mime, server)
                                        .then( function(response) {
                                            // All Good
                                        }, function(error) {
                                            // Error
                                        });
                    }
                  }
                }, function (error) {
                      // console.log('Error: ' + error);
                }
              );
Mr-Anonymous commented 6 years ago

To resolve it, I added another loop that processes upto 6 images at a time so the later ones in the queue are not timed out.