0

I am using the removedfile function of DropzoneJs to delete the newly uploaded file, but it only deletes the first file, it has a problem with my renameFilename function.

Everything works fine if I don't rename the image, but I want the image not to have the same name. I definitely have an error when assigning the value to filename.

After uploading multiple images I press delete and it just deletes the first image, leaving the remaining images, "request" takes the name of the first photo.

Dropzone.autoDiscover = false;

var name;

var Dropzone = new Dropzone(".dropzone", {
    maxFileSize: 50,
    acceptedFiles: ".jpg,.png",
    addRemoveLinks: true,
    renameFilename: function (filename) {
        name  = new Date().getTime() + '-' + filename;
        return name;
    },
    removedfile: function(file){
        $.ajax({
            type: 'POST',
            url: route('product.images.remove'),
            data:{
                name: name
            },
            dataType: 'html'
        });
        var _ref;
        return(_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
    }
});
f-CJ
  • 4,235
  • 2
  • 30
  • 28
newsshare24h
  • 69
  • 1
  • 11

1 Answers1

0

Assuming you are working with the latest version of Dropzone.js, renameFilename has been renamed to: renameFile

Eric Tung
  • 310
  • 2
  • 7