![](/img/trans.png)
[英]How to allow resubmission of file uploads after failure with Dropzone.js?
[英]How can we resume failed uploads? - DropZone.JS
我使用DropzoneJs- https://github.com/enyo/dropzone我想自動恢復失敗的上傳。
我檢查了這個問題,並為此找到了解決方案
https://github.com/enyo/dropzone/issues/1150#issuecomment-253480122
這是我現有的Dropzone配置(我嘗試添加代碼,但無法成功)
var total_photos_counter = 0;
Dropzone.options.myDropzone = {
uploadMultiple: true,
parallelUploads: 1,
maxFilesize: 100,
previewTemplate: document.querySelector('#preview').innerHTML,
addRemoveLinks: true,
dictRemoveFile: 'Resmi Sil',
dictFileTooBig: 'Dosya 100 MB den büyük. Daha küçük boyutlu bir fotoğraf yükleyiniz' ,
acceptedFiles: '.jpeg,.jpg,.png,.zip',
dictCancelUpload: 'Yüklemeyi İptal Et',
dictInvalidFileType: "Bu tip bir dosyayı yükleyemezsiniz. Sadece resim ve Zip yükleyebilirsiniz.",
timeout: 100000000,
init: function () {
this.on("removedfile", function (file) {
$.post({
url: '/images-delete',
data: {id: file.name, _token: $('[name="_token"]').val()},
dataType: 'json',
success: function (data) {
total_photos_counter--;
$("#counter").text("# " + total_photos_counter);
}
});
});
},
success: function (file, done) {
total_photos_counter++;
$("#counter").text("# " + total_photos_counter);
},
error: function (file,response) {
var dropzoneFilesCopy = dropzone.files.slice(0);
dropzone.removeAllFiles();
$.each(dropzoneFilesCopy, function(_, file) {
if (file.status === Dropzone.ERROR) {
file.status = undefined;
file.accepted = undefined;
}
dropzone.addFile(file);
});
}
};
如何將這個解決方案添加到我的配置js中。 僅添加到文件末尾對我來說沒有任何意義。
var dropzoneFilesCopy = dropzone.files.slice(0);
dropzone.removeAllFiles();
$.each(dropzoneFilesCopy, function(_, file) {
if (file.status === Dropzone.ERROR) {
file.status = undefined;
file.accepted = undefined;
}
dropzone.addFile(file);
});
你可以使用它里面init
您的懸浮窗配置的部分,使用errormultiple
事件里面init
像下面
init: function () {
this.on("removedfile", function (file) {
$.post({
url: '/images-delete',
data: {id: file.name, _token: $('[name="_token"]').val()},
dataType: 'json',
success: function (data) {
total_photos_counter--;
$("#counter").text("# " + total_photos_counter);
}
});
});
this.on('errormultiple',function(files, response){
var dropzoneFilesCopy = files.slice(0);
myDropzone.removeAllFiles();
$.each(dropzoneFilesCopy, function(_, file) {
if (file.status === Dropzone.ERROR) {
file.status = undefined;
file.accepted = undefined;
}
myDropzone.addFile(file);
});
});
},
注意:您需要在正在使用的腳本內相應地更改變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.