简体   繁体   中英

How to skip or remove some file at run time from uploading list

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();
    }
});

PS I haven't run the code, just sharing the idea.

You should just call data.abort(); It should do the work.

Or you can also call data.context.remove()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM