Home Forums Porto Template changed name from dropzone where file already exists

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #10031175
    pellesoft
    Participant

    https://www.dropbox.com/s/taxgcdjctbrju2b/Sk%C3%A4rminspelning%202019-11-06%20kl.%2017.26.57.mov?dl=0

    Hi, is it possible to change the code so that if the filename is changed when uploaded so that it could be deleted again?

    See attached movie for the scenario.

    Best regards
    Pelle


    #10031176
    pellesoft
    Participant

    I tried to add
    `
    – file.previewElement.querySelector(‘[data-dz-name]’).innerHTML = imgName;
    – file.name = imgName;
    `
    It looks right when hovering over the image but when the delete-action starts, it does not give me the right name so wrong image are delete.

    Sample:

    adding 1.jpg, adding 1.jpg (and system renames it to 1_1.jpg)
    when press delete on 1_1.jpg it deletes 1.jpg (fetch from file.name).


    #10031177
    pellesoft
    Participant

    Found this, tried but just got error on creating object

    https://github.com/enyo/dropzone/issues/1399

    Regards
    Pelle


    #10031179
    pellesoft
    Participant

    Damn, i fixed it! I am not sure if you are interested in how i did – but that is a nice manner to share 🙂

    1. When uploading the file, it goes to another page and upload it / in my case – i changed the name if the same name existed and returned it.
    2. Dropzone recieved it and i saved the name and path

    
    file.previewElement.querySelector('[data-dz-name]').innerHTML = imgName;
                        file.name = imgName;
    
                        // Set the returned filename to the record if we are deleting it before postback
                        file.previewElement.id = imgName;

    3. when the delete action starts, check the object and fetch the filename from there.. Using this function, i was able to delete the correct file.

    
    // getting the filename from another place to be sure we delete the right file. It could be a pre-loaded file
                        // but also a newly added file that was just added and the page is not re-loaded with the data.
                        var thefileid = jQuery(file.previewElement).find('.dz-filename span').html();
       
                        //
                        if (confirm('You are about to delete the file ' + thefileid + '. Do you want to continue?')) {
                            // true
                        } else {
                            return;
                        }

    I send you a short movie on this ..
    https://www.dropbox.com/s/viud164o371y4b9/Sk%C3%A4rminspelning%202019-11-06%20kl.%2020.22.43.mov?dl=0

    Please feel free to make it even better if you have any ideas.

    Regards
    Pelle


    • This reply was modified 1 week, 5 days ago by  pellesoft.
    #10031181
    Support2
    Keymaster

    Hello Pelle,

    My suggestion for you is generate a unique/random filename at server side and then return the new filenames for use inside the removedfile method.

    Here is an example that I found on google:
    https://stackoverflow.com/questions/24859005/dropzone-js-how-to-change-file-name-before-uploading-to-folder

    We hope this helps.

    Kind Regards,

    Rodrigo.


Viewing 5 posts - 1 through 5 (of 5 total)