Blueimp 文件上传:上传前从文件列表中删除文件

2024-05-06

在提交要上传的表单之前,如何从 Blueimp 插件的选定文件列表中删除文件。我试过这个答案 https://stackoverflow.com/questions/18267958/how-to-remove-file-from-the-queue-to-stop-upload-before-upload-starts-in-blueimp但它只是从 UI 中删除文件而不是从队列中删除文件。

这是我的代码

$(function(){
            $("#UploadPhotos").click(function(){
                $("#ItemPhotos").click();
            });
            $('#ItemPhotos').fileupload({
                    url: "${pageContext.servletContext.contextPath}/XYZ",
                    //dataType: 'json',
                    autoUpload: false,
                    acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
                    maxFileSize: 5000000, // 5 MB
                    // Enable image resizing, except for Android and Opera,
                    // which actually support image resizing, but fail to
                    // send Blob objects via XHR requests:
                    disableImageResize: /Android(?!.*Chrome)|Opera/
                        .test(window.navigator.userAgent),
                    previewMaxWidth: 171,
                    singleFileUploads:false,
                    previewMaxHeight: 180,
                    previewCrop: true
                }).on('fileuploadadd', function (e, data) {
                    data.context = $('<div/>').appendTo('#FilesListThumb');
                    $.each(data.files, function (index, file) {
                        var node = $('<div><h6>X</h6></div>').addClass("thumbnail-ib");
                        node.appendTo(data.context);
                        node.find("h6").click(function(){
                            node.remove();
                        });
                    });
                    $("#itemSellForm").submit(function(){
                        data.formData = $("#itemSellForm").serializeArray();
                        data.submit();
                        return false;
                    });                        
                }).on('fileuploadprocessalways', function (e, data) {
                    var index = data.index,
                        file = data.files[index],
                        node = $(data.context.children()[index]);
                    if (file.preview) {
                        node
                            .addClass("thumbnail")
                            .append(file.preview);
                    }
                    if (file.error) {
                        node
                            .addClass("thumbnail")
                            .append($('<span class="text-danger"/>').text("Upload Failed"));
                    }
                }).on('fileuploadfail', function (e, data) {
                    $.each(data.files, function (index, file) {
                        var error = $('<span class="text-danger"/>').text('File upload failed.');
                        $(data.context.children()[index])
                            .append('<br>')
                            .append(error);
                    });
                }).on("fileuploaddone",function(e,data){
                  //  sendData = false;
                 alert("done");
                });
        });

在这里,当我单击 h6 缩略图时,它仅从 ui 中删除,而不是从 ifles 列表中删除


每个 BlueImp 回调都有 2 个参数:event and a data object.

The data对象包含一个files您可以编辑该数组以更改将上传的文件。因此,如果您删除这些数组元素之一(array.pop,或其他方法...)在提交您的请求之前,可以认为是removed.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Blueimp 文件上传:上传前从文件列表中删除文件 的相关文章

随机推荐