dropzone.js最大文件大小触发queuecomplete事件

问题描述 投票:0回答:1

我有一个用JavaScript实现的Dropzone。我想处理用户尝试上传超过最大文件大小的文件的情况。具体来说,我想删除文件并显示模式警报,告知用户有关该问题的信息。 我的问题是,当某人上传超过最大文件大小的文件时,它会触发queuecomplete事件,而窗口会导航到另一个页面。如何在不触发Queuecomplete事件的情况下管理此问题?

这是滴区:

var myDropzone = new Dropzone("#dropzoneFileUpload", { url: appRootUrl + "someUrl", autoProcessQueue:false, paramName: "file", addRemoveLinks: true, dictRemoveFile: "Eliminar fichero", dictCancelUpload: "Cancelar subida", maxFiles: 20, parallelUploads: 20, maxFilesize: 50, init: function () { thisDropzone = this; }, accept: function(file, done) { var thumbnail = $('.dropzone .dz-preview.dz-file-preview .dz-image:last'); //Cuando alguien sube un archivo al dropzone este switchcase pinta imagenes segun el tipo de archivo switch (file.type) { case 'application/pdf': thumbnail.css('background', 'url(https://upload.wikimedia.org/wikipedia/commons/thumb/9/94/PDF_icon_-_grey-red_-_16px.svg/120px-PDF_icon_-_grey-red_-_16px.svg.png?20210526135026)'); break; case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': thumbnail.css('background', 'url(https://upload.wikimedia.org/wikipedia/commons/f/fb/.docx_icon.svg)'); break; case 'application/vnd.ms-excel': thumbnail.css('background', 'url(https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Xls_icon_%282000-03%29.svg/1024px-Xls_icon_%282000-03%29.svg.png)'); break; default: break; } if (file.size > this.options.maxFilesize * 1024 * 1024) { thisDropzone.removeFile(file); $("#aviso").text("El archivo '"+file.name+"' excede el tamaño máximo permitido (" + this.options.maxFilesize + "Mb)."); $("#myModalAviso").modal("show"); } else if (checkFileName(file.name)) { thisDropzone.removeFile(file); $("#aviso").text("El archivo '"+file.name+"' no se admite debido a que el nombre del archivo contiene un punto."); $("#myModalAviso").modal("show"); return; } else{ done(); } } }); myDropzone.on("queuecomplete", function() { let detalle = $("#detalle").val(); if(detalle == "true"){ window.location.href = "/someUrl/"+$("#id").val(); } else{ window.location.href = "/someUrl/"; } });

这是我尝试的其他一些方法:
myDropzone.on("error", function(file, message) { 
    alert(message);
    this.removeFile(file); 
});

myDropzone.on("addedfile", function(file) {
    event.preventDefault()
    if (file.size > this.options.maxFilesize * 1024 * 1024) {
       thisDropzone.removeFile(file);
        $("#aviso").text("El archivo '"+file.name+"' excede el tamaño máximo permitido (" + this.options.maxFilesize + "Mb).");
        $("#myModalAviso").modal("show");
    }
});

谢谢你
	

当您调用

removeFile
javascript jquery dropzone
1个回答
0
投票
canceled

事件,如果dropzone中没有更多文件,则会触发

queuecomplete
事件。
一个解决方案是,在您的事件处理程序中,请在重定向用户之前检查Dropzone中是否有文件。
queuecomplete

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.