knownasilya/ember-plupload

An upload endpoint responding with a 500 status code does not trigger `onerror`

Opened this issue · 6 comments

Hi Tim,
I started testing out the onerror callback you added for 1.13. Thanks for adding it!

The server endpoint I am uploading to responds with a 500 when the file in question does not meet certain criteria.
Unfortunately, the bundled version of moxie.js does not trigger errors for 500 responses from the server. I am guessing ember-plupload relies on plupload.js to bubble the errors up from failed XHR requests. Thus, onerror does not fire. (as background the actions are being handled in my route and the instantiation of ember-pluupload occur's in that route's template).

Is there an expected response format server's should give for failed file uploads?

It looks like it bypasses fileUploaded and goes straight to https://github.com/moxiecode/plupload/blob/master/js/plupload.dev.js#L1408-L1411

Looking through the code I wrote to handle this, it seems like onerror doesn't fire, but the file is rejected. This is currently expected behavior. Would you like to change this so onerror is always fired?

The code path in question switches on whether there is a file associated with the error: https://github.com/paddle8/ember-plupload/blob/master/addon/system/upload-queue.js#L242, which means that https://github.com/paddle8/ember-plupload/blob/master/addon/system/upload-queue.js#L275-L276 (which triggers the onerror event) is never triggered.

Thanks for the explanation.
I was expecting onerror to be fired whenever each file upload request fails.
I think always firing onerror would be helpful for my use case. I think it would be useful to have some sort of callback in order to keep the invalid files around so they could be retried. Sounds like a bit different feature though.

The current behavior handles network errors or other misc. problems well whereas what I am looking for is something like onreject where the endpoint validates the provided file.
I'll close the issue for now as I think I can achieve my use case by using pluploader directly.

@efx you can actually retry files by the following:

export default Ember.Route.extend({
  actions: {
    uploadFile(file) {
      file.upload().then(null, function () {
         // You can stash the file here and call file.upload on it again when needed
      });
    }
  }
});