I'm using blueimp plugin
https://github.com/blueimp/jQuery-File-Upload/wiki/API
I need to remove some files, during run time, from the queue.
When status code 17
(File Already Exits) from the server, then that particular file should be removed.
This is what I have tried so far to no success.
$('#fileupload').fileupload({
url: 'url.php',
maxChunkSize: 65536, // 120 KB,
maxRetries: 10,
dataType: 'json',
multipart: false,
sequentialUploads: true,
add:function(){........},
done:function(){........}
}).on('fileuploadchunkdone', function (e, data) {
if(data.result.status == 17){
var currentFileObject = data.files[0];
var index = data.originalFiles.indexOf(currentFileObject); // find index in originalFiles
data.originalFiles.splice(0,index);
//data.files.length = 0; // if i uncomment this line some error will come, like undefined fileName
data.submit();
}
});
I am removing the file by finding
in data.originalFiles
NOTE:(please note) i'm not using any ui provided by plugin (cancel, update, crop image, thumbnail)
etc
created fiddle for experimenting:http://jsfiddle.net/ChJ9B/219/
Please help me to solve this problem.
Thanks in advance !!!!
You can use the .abort()
method to cancel the uploading of the files.
In your case, you can save all the fileupload request to an object and then abort the specific one.
filesList.forEach(function(elm) {
jqXHR[elm.name] = $('#fileupload').fileupload('send', {files: elm});// you should save some id or timestamp
});
and then in the callback to the fileuploadchuckdone
event, you can look for the name of the file and then abort from the jqXHR
object.
function (e, data) {
if(data.result.status == 17){
var currentFileName = data.files[0].name; // read the name somehow?
jqXHRMap[currentFileName].abort();
}
});
P.S. I haven't run the code, just sharing the idea.