How can I run a download file using Valums Ajax File-Uploader?

When using the Valums Ajax file downloader, how can I initiate the download?

The default behavior is that the download starts immediately after the user selects a file. I want this to not happen, and instead start the download when the user clicks a separate “Download” button after they select the file.

I looked at the code and found that the download starts with an event changerelated to file input. I started by adding return false;to the function onSubmit, and then attached the click event to another button that raised the change event:

$('#startUpload').on('click', function() {  
    // some conditionals
    $('input[name="file"]').trigger('change');  
});

This does not work. It opens the file menu again.

How can I prevent the download right after the user selects a file and instead launches it when the user clicks on another button?

+5
source share
2 answers

To do this, you will have to modify the file-uploader.js file. On line 309, change the onChange function to return false. Then add the following function above it so that the code becomes:

startUpload: function(){
    this._onInputChange(this._button.getInput());
},
_createUploadButton: function(element){
    var self = this;

    return new qq.UploadButton({
        element: element,
        multiple: this._options.multiple && qq.UploadHandlerXhr.isSupported(),
        onChange: function(input){
            return false;
        }
    });
},

Then, in your HTML file, by clicking a button or any other event, call

uploader.startUpload();

where uploader is the name of your qq.FileUploader () object.

Hope that helps :)

+3
source

Valums Ajax File Loader now supports this feature. You can load the queue files and load the trigger at the click of a button

 var uploader2 = new qq.FileUploader({
    element: $('#manualUploadModeExample')[0],
    action: "success.html",
    autoUpload: false,
    demoMode: true,
    uploadButtonText: "Select Files"
});

$('#triggerUpload').click(function() {
    uploader2.uploadStoredFiles();
});

See this link for more details: valulus file uploder

+2
source

All Articles