jQuery-File-Upload icon indicating copy to clipboard operation
jQuery-File-Upload copied to clipboard

Callback from a file delete ?

Open jcorreia opened this issue 15 years ago • 10 comments

Hi, Is there any callback from this page https://github.com/blueimp/jQuery-File-Upload/wiki/Options that is triggered whenever a file is deleted ?

I´m trying to remove a file from a database when a file delete occurs.

Thanks

jcorreia avatar Jul 05 '11 11:07 jcorreia

Ok, I found something :

First you edit the Javascript Template to add an hidden field with the filename:

<script id="template-download" type="text/x-jquery-tmpl">
    <tr class="template-download{{if error}} ui-state-error{{/if}}">
        {{if error}}
            ...
        {{else}}
            ...
            <td class="name">
                <a href="${url}"{{if thumbnail_url}} target="_blank"{{/if}}>${name}</a>
                ** <input type="hidden" name="file_name" value="${name}" /> **
            </td>
            ...
        {{/if}}
        ...
    </tr>
</script>

now in the file jquery.fileupload-ui.js in the destroy callback :

destroy: function (e, data) {
                var that = $(this).data('fileupload');

                /** Get the filename **/
                var fileName = $("input[name='file_name']", data.context).val();

                if (data.url) {
                    $.ajax(data)
                        .success(function () {
                            that._adjustMaxNumberOfFiles(1);
                            $(this).fadeOut(function () {
                                $(this).remove();
                            });

                            //--> Delete the file ine he database with the new var fileName
                        });
                } else {
                    data.context.fadeOut(function () {
                        $(this).remove();
                    });
                }
            }

If you're doing a multiple upload you can use this code for the hidden field :

<input type="hidden" name="file_name[]" value="${name}" />

now in your $_POST['file_name'] you will have an array.

Hope it can help you and sorry for my english :)

Kaimite

Kaimite avatar Jul 05 '11 14:07 Kaimite

Thanks !!! I will try this and give some feedback :)

jcorreia avatar Jul 05 '11 15:07 jcorreia

Thanks !! it worked very well, and give some ideas to future workarounds. excellent work :)

jcorreia avatar Jul 05 '11 16:07 jcorreia

You're welcome :)

Kaimite avatar Jul 05 '11 16:07 Kaimite

There is another option:

$('#fileupload').bind('fileuploaddestroy', function (e, data) {
        // YOUR CODE
    });

Regards

isaacsf avatar Dec 15 '11 09:12 isaacsf

Thank's :) I'll try this.

See You, Kaimite

Kaimite avatar Dec 15 '11 09:12 Kaimite

@isaacsf

Thanks, it worked. Couldn't find documentation on it...so I appreciate you listing this binding here.

jeffjohnson avatar Sep 06 '12 00:09 jeffjohnson

Up! How can I get the name of the deleted file with bind('fileuploaddestroy', function (e, data) ?

Sispheor avatar Oct 16 '12 15:10 Sispheor

@Sispheor

Try this...

$('#fileupload').bind('fileuploaddestroy', function (e, data) {
    var filename = data.url.substring(data.url.indexOf("=") + 1);
});

jeffjohnson avatar Oct 16 '12 15:10 jeffjohnson

It work well thanks JeffJohnson !!

Sispheor avatar Oct 17 '12 08:10 Sispheor