Jquery Blueimp - Remove file from queue

I must first say that I have all the solutions on stackoverflow, but without any success. My problem is very simple. I need to remove files from the queue before / after clicking the Start Download button which downloads all files with one click .... My code is:

            var indexProgressBar = 1;

        $('#fileupload').fileupload({
            autoUpload: false,
            url: url,
            dataType: 'json',
            sequentialUploads: true,
            singleFileUploads: true,
        }).on('fileuploadadd', function (e, data) {

            $.each(data.files, function (index, file) {
                var file = data.files[0];
                file.uploadID = 'progress' + indexProgressBar;
                file.uploadDivID = 'itemDiv' + indexProgressBar;
                file.fileId = 'deleteButton' + indexProgressBar;

                var node = $('<div id=' + file.uploadDivID + ' style="margin-bottom:20px; font-size:11px;"><span class="progress-filename" style="width:180px;">' + file.name + '</span ></div>');
                node.append('<img src="" id=' + file.fileId + ' alt="delete" /><br />');
                node.append('<div id="' + file.uploadID + '" class="progress" style="margin-bottom:0px; width:200px;" ><div class="progress-bar progress-bar-success"></div></div>');
                node.appendTo($('#filesToUpload'));

                node.find("img").click(function(){
                    node.remove();
                    });
                });

                indexProgressBar++;

                //upload Manualy
                $("#uploadBtn").on('click', function () {
                    data.submit();
                });
        }).on('fileuploaddone', function (e, data) {
            //upload Manualy
            $("#uploadBtn").off('click');

            var uploadDivID = data.files[0].uploadDivID; // returns 'someidentification'

            if (data.result.status == "OK") {
                $('#' + uploadDivID).fadeOut(1000, function () { $(this).remove(); });
            }
            else {
                $('#' + uploadDivID).append("<div style='color:red'>Error: " + data.result.errorMsg + "</div>");
            }

        }).on('fileuploadprogress', function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            var progressID = data.files[0].uploadID; // returns 'someidentification'

            $('#' + progressID + ' .progress-bar').css(
                'width',
                progress + '%'
            );

            //}).on('fileuploadprogressall', function (e, data) {
            //var progress = parseInt(data.loaded / data.total * 100, 10);
            //    $('#progress .progress-bar').css(
            //        'width',
            //        progress + '%'
            //    );

        }).prop('disabled', !$.support.fileInput)
            .parent().addClass($.support.fileInput ? undefined : 'disabled');

      

The problem is that this is only visually deleting the file, but I need to remove it from data.files somehow, but I need all files to be loaded with one button ... Hmm ... Thanks for your help.

+3


source to share


1 answer


I found how it works perfectly. With a little help, the array works fine.

            var a = [];

        var indexProgressBar = 0;

        $('#fileupload').fileupload({
            autoUpload: false,
            url: url,
            dataType: 'json',
            sequentialUploads: true,
            singleFileUploads: true,
        }).on('fileuploadadd', function (e, data) {

            $.each(data.files, function (index, file) {
                var file = data.files[0];
                file.uploadID = 'progress' + indexProgressBar;
                file.uploadDivID = 'itemDiv' + indexProgressBar;
                file.fileId = 'deleteButton' + indexProgressBar;

                var node = $('<div id=' + file.uploadDivID + ' style="margin-bottom:20px; font-size:11px;"><span class="progress-filename" style="width:286px; display:inline-block;">' + file.name + '</span ></div>');
                node.append('<img src="/_layouts/15/SkodaAuto.MarketingDatabank2.Project/Images/Icons/Delete-12.png" id=' + file.fileId + ' fileId=' + indexProgressBar + ' alt="delete" style="cursor:pointer;" /><br />');
                node.append('<div id="' + file.uploadID + '" class="progress" style="margin-bottom:0px; width:300px;" ><div class="progress-bar progress-bar-success"></div></div>');
                node.appendTo($('#filesToUpload'));

                node.find("img").click(function () {
                    a.push(file.fileId);
                    //data.files.splice($("#" + file.fileId).attr("fileId"), 1);

                    $(this).fadeOut(500, function () {
                        node.remove();
                    })

                });
            });

            indexProgressBar++;

            //upload Manualy
            $("#uploadBtn").on('click', function () {
                if ($.inArray(data.files[0].fileId, a) == -1) {
                    data.submit();
                }
            });
        }).on('fileuploadsend', function (e, data) {
            if ($.inArray(data.files[0].fileId, a) != -1) {
                return false;
            }
        }).on('fileuploaddone', function (e, data) {
            //upload Manualy
            $("#uploadBtn").off('click');

            var uploadDivID = data.files[0].uploadDivID; // returns 'someidentification'

            if (data.result.status == "OK") {
                $('#' + uploadDivID).fadeOut(1000, function () { $(this).remove(); });
            }
            else {
                $('#' + uploadDivID).append("<div style='color:red'>Error: " + data.result.errorMsg + "</div>");
            }

        }).on('fileuploadprogress', function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            var progressID = data.files[0].uploadID; // returns 'someidentification'

            $('#' + progressID + ' .progress-bar').css(
                'width',
                progress + '%'
            );

            }).on('fileuploadprogressall', function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
                $('#progress .progress-bar').css(
                    'width',
                    progress + '%'
                );
        }).prop('disabled', !$.support.fileInput)
            .parent().addClass($.support.fileInput ? undefined : 'disabled');

      

first I need to specify an array

var a = [];

      

Further

 a.push(file.fileId);

      



and then

//upload Manualy
                $("#uploadBtn").on('click', function () {
                    if ($.inArray(data.files[0].fileId, a) == -1) {
                        data.submit();
                    }
                });

      

and this one

.on('fileuploadsend', function (e, data) {
                if ($.inArray(data.files[0].fileId, a) != -1) {
                    return false;
                }
            }).

      

And what is it ... Thanks

+4


source







All Articles