I'm trying to implement file upload with blueImp jQuery-File-Upload using angularJS.
The file upload is supposed to support chunked upload and automatically resume if a chunk upload fails.
Uploading in chunks works fine. The problem I face now is when an error occurs the automatic resume (chunkfail method) is invoked and restarts an upload call with the rest of the data being uploaded all at once! No more chunking occurs when automatic resume takes place. Here's my code based on the example shown on github:
.controller('MyFileUploadController', ['$scope','$http',
function ($scope, $http) {
// setting upload properties:
$scope.options = {
url: myUploadUrl,
maxChunkSize: 100*1024 //100kB,
maxRetries: 100,
retryTimeout: 500,
chunkfail: function (e, data) {
if (e.isDefaultPrevented()) {
return false;
}
var that = this,
scope = data.scope;
if (data.errorThrown === 'abort') {
scope.clear(data.files);
return;
}
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'),
retries = data.retries || 0;
var retry = function () {
var req = {
method: 'POST',
url: filecheckUrl,
headers: {
'Content-Type': 'application/json'
},
data: {file: data.files[0].name}
};
$http( req ).success(function(respData, status, headers, config) {
data.uploadedBytes = respData && respData.size;
data.data = null;
data.submit();
}).error(function(respData, status, headers, config) {
fu._trigger('fail', e, data);
});
if (data.errorThrown !== 'abort' && data.uploadedBytes < data.files[0].size && retries < fu.options.maxRetries) {
retries += 1;
data.retries = retries;
window.setTimeout(retry, retries * fu.options.retryTimeout);
return;
}
data.retries = null;
$.blueimp.fileupload.prototype.options.fail.call(this, e, data);
}
};
What am I missing to have the data.submit()
call in chunkfail
resuming the upload with the next chunk instead of all the remaining at once?