Search code examples
jqueryfile-uploadblueimp

blueimp - jquery fileupload onClick event


We are using Blueimp Jquery File Upload.

How do we add a button to fire the upload?

Right now the upload occurs as soon as a user selects a file. We would like to have the user select files then click a UPLOAD NOW button.

I have changed the JS file, turned on the autoUplaod to false, but can figure out how to get the OnClick to work.

<script>
$(function () {
    $('#fileupload').fileupload({
        dataType: 'json',
        done: function (e, data) {
            $.each(data.result, function (index, file) {
                $('<p/>').text(file.name).appendTo(document.body);
            });
        }
    });
});
</script> 

Solution

  • Maybe you are looking for add function callback:

    $(function () {
        $('#fileupload').fileupload({
            dataType: 'json',
            done: function (e, data) {
                $.each(data.result, function (index, file) {
                    $('<p/>').text(file.name).appendTo(document.body);
                });
            },
            add:function (e, data) {
               $("#uploadBtn").off('click').on('click',function () {           
                 data.submit();
               });
            }
        });
    });