Question

I am implementing the s3 file uploader and we are trying to request a key from the server for a file upload, but a the same time validate the parameters that are being additionally passed up so that the user doesn't bother uploading the file if something like the file name is invalid:

objectProperties: {
  key: function(fileId) {
    var keyRetrieval = new qq.Promise(),
    filename = $("#fineuploader-s3").fineUploader("getName", fileId);

    $.post("/path_to_initiate_file_upload", { name: filename, current_folder: null })
      .done(function(data) { keyRetrieval.success(data.key); })
      .fail(function() { keyRetrieval.failure(); });

    return keyRetrieval;
  }
}

At first I ran into issue #1071 and I have since just commented out that line for the time being, but after that I am now hitting the point where when I return a non-200 response it just appears to hang. Is there anything I can do in the key retrieval failure function to let Fine Uploader know that this particular upload failed and display an error message?

I am aware of the "validate" event for a file, but I would prefer not to require two separate ajax calls before each file upload. Is it possible to call the validate event, retrieve the custom file key from the result of that call and then store it so that it is used as the key for uploading the file to s3?

Was it helpful?

Solution

This was a bug in Fine Uploader S3, currently fixed in the develop branch. The fix will go out tomorrow with Fine Uploader 4.2. Note that issue #1071, which you mentioned, will also be fixed as part of 4.2.

Now, when a key lookup function returns a qq.Promise, and the fulfillment of the promise results in a failure(), the associated upload will, in turn, be failed as well.

I would suggest you NOT use your key lookup function as an opportunity to validate your file. You really should be using the validate callback(s) for this. Why? Well, if you decide to "invalidate" a file in your key retrieval function and you have autoRetry enabled, Fine Uploader S3 will attempt to retry until all auto retries are failed. Hardly what you want when invalidating a file. I don't expect to change this behavior as the expectation is that a failed key retrieval is something we would want to re-attempt. Also, if you invalidate a file via your key retrieval function, the status of the file will be qq.status.UPLOAD_FAILED instead of what you might want (qq.status.REJECTED). Why? Fine Uploader S3 doesn't know that you invalidate the file, just that key retrieval failed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top