我们如何恢复失败的上传? - 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);
});
您可以在 Dropzone 配置的 init
部分中使用它,在 init
中使用 errormultiple
事件,如下所示
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);
});
});
},
注意:您需要在您正在使用的脚本中相应地更改变量。
我使用 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);
});
您可以在 Dropzone 配置的 init
部分中使用它,在 init
中使用 errormultiple
事件,如下所示
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);
});
});
},
注意:您需要在您正在使用的脚本中相应地更改变量。