2

I'm trying to kill the upload as soon as an exception occurs. The "fileuploadchunkdone" event handler allows me to capture the "error" json sent from the server for every single chunk. Ideally, I would like to abort the upload as soon as an exception occurs. I need to do this check for every chunk since I need to log the error and display the error code when the exception occurs. However, I am not able to kill the exception by calling data.jqXHR.abort(). It just continues going through every chunk. Any ideas? Here is the code for that event handler:

.on('fileuploadchunkdone', function (e, data) {
                if (!data.result.success) {
                    running--;
                    var errMsg = "";
                    if (data.result != null) {
                        if (data.result.message != null) {
                            errMsg += data.result.message;
                        }
                        if (data.result.error != null)
                            errMsg += data.result.error;
                    }
                    layoutService.showErrorDialog(errMsg);

                    data.jqXHR = data.abort();
                    window.removeXHRfromPool(data);

                    if (running == 0) {
                        $('#dlgProgress').parent().hide();
                        $('#progresses').empty();
                    }
                }
        })
TheDude
  • 1,421
  • 4
  • 29
  • 54
  • Similar problem here. I've tried aborting in chunksend and chunksuccess event with no effect. Also tried calling abort in a setTimeout, but that didn't help either. – Doug Domeny Nov 21 '13 at 19:13

1 Answers1

1

If the chunk-send callback function returns false, the entire upload request is aborted. I'm adding a custom property abortChunkSend to signal from the chunk-done event to cancel on the next chunk-send event.

Example,

.on("fileuploadchunksend", function (e, data)
{
    var abortChunkSend = data.context[data.index].abortChunkSend;
    if (abortChunkSend)
    {
        return false;
    }
})
.on("fileuploadchunkdone", function (e, data)
{
    if (data.result)
    {
        for (var index = 0; index < data.result.files.length; index++)
        {
            var file = data.result.files[index];
            if (file.error)
            {
                data.context[index].abortChunkSend = true;
            }
        }
    }
})

Reference blueimp documentation on fileuploadchunksend.

Doug Domeny
  • 4,410
  • 2
  • 33
  • 49