2

Goal: Check size of image (using PhoneGap Build) and return if image is too large.

Problem: Error is thrown when image is out of bounds, but the upload continues anyway. Even though similar checks in the same function actually do return.

for (var i = 0; i < this.pageContainer.items.length; i++) {
  resolveLocalFileSystemURL(this.pageContainer.items.items[i].imageURI, function(fileEntry){
    fileEntry.file(function(fileObj){
      if (maxUploadSize <= fileObj.size){
        Ext.Msg.alert("Error", "Chosen image is too large. Choose a different image.");   
        return;
      }
    })
  })
}
// Only continue with a valid internet connection
if(!at.util.Connection.isOnline()) {
  return;
}

// Upload the first page
this.timeStamp = at.util.Navigation.showLoading();

firstPageURI = this.pageContainer.items.items[0].imageURI;

globalDocumentUploadComponentId = this.getId();

// Call the upload function
at.util.Images.uploadDocument(globalUploadDocumentSuccess, firstPageURI, documentTypeId, this.affectedEntityId, issuedDate, expirationDate, neverExpire, issuingCountry, issuingState, this.restrictionId, null);

Edit: I thought it was different than the proposed article since resolveLocalFileSystemURL(Url, resOnSuccess, resOnError); and I thought my if statement was taking the place of the on error.

moby
  • 149
  • 2
  • 9
  • 3
    I'm guessing `resolveLocalFileSystemURL(...)` or `fileEntry.file(...)` or both are async. – Corey Ogburn Mar 07 '16 at 20:41
  • resolveLocalFileSystemURL is, yes. – moby Mar 07 '16 at 20:44
  • I just saw three other questions like this in the last hour. – rgajrawala Mar 07 '16 at 20:44
  • You are `return`ing from the `function(fileEntry){...}` function, not the outer function. The solution here is to keep track of the any failures and have the last iteration of the `resolveLocalFileSystemURL` callback call `uploadDocument` if there were no failures. I'm not 100% sure if the proposed duplicate is the best match for this question, but it might be. – apsillers Mar 07 '16 at 20:49

0 Answers0