Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can we resume failed uploads? #1150

Closed
CitizenBeta opened this issue Dec 8, 2015 · 8 comments
Closed

How can we resume failed uploads? #1150

CitizenBeta opened this issue Dec 8, 2015 · 8 comments

Comments

@CitizenBeta
Copy link

Is there a way to make it so that failed uploads can be resumed or retried?

@40rn05lyv
Copy link

40rn05lyv commented Oct 4, 2016

Hi, did you solve this problem?

@CitizenBeta
Copy link
Author

@40rn05lyv
Copy link

40rn05lyv commented Oct 13, 2016

My workaround (remove all files, reset status and add them back):

let 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);
});

@ademchenko
Copy link

ademchenko commented Aug 1, 2018

40rn05lyv, I'm not sure if you're using jquery object under $ sign, but if so there's an innacuracy in the solution. Each method's callback on arrays receives array index as the fist parameter and value as the secound. So the solution should be:

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);
});

@serhatculhalik
Copy link

serhatculhalik commented Aug 1, 2018

@ademchenko

Should I add this snippet to end of my dropzone.config file just to make it work?
Or Should I put under Dropzone.options.MyDropzone? Please advise. My custom config file is. I just added your snippet to the end of my file but it didn't work.

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);
    }
};


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);
});

@nkogit
Copy link

nkogit commented Apr 19, 2019

Try changing the file status from "error" to "queued" on upload error and then calling processQueue() to continue processing.

dropzone.on("error", function(file, errorMessage, xhr) {
    file.status = "queued";
    dropzone.processQueue();
});

Add infinite loop protection as needed.

@orion3dgames
Copy link

orion3dgames commented Feb 10, 2020

@nkogit solution works well. Thanks to him. Below an example with infinite loop protection.

var retryTimes = 3;

dropzone.on("processing", function(file, errorMessage, xhr) {
    this.options.autoProcessQueue = true;
});

dropzone.on("success", function(file, errorMessage, xhr) {
    this.removeFile(file);
},

dropzone.on("error", function(file, errorMessage, xhr) {
    if(!file.retryTimes){
        file.retryTimes = 0;
    }

    file.retryTimes = file.retryTimes + 1;

    if(file.retryTimes < retryTimes) {
        file.status = Dropzone.QUEUED
        // dropzone.processQueue(); // No need this as I already have autoProcessQueue = true
    }else{
        this.removeFile(file);
    }
});

@enyo enyo closed this as completed Feb 5, 2021
@WalkUnderPressure
Copy link

WalkUnderPressure commented Aug 22, 2022

file.status = "QUEUED";

file.status = Dropzone.QUEUED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants