最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I trigger the upload file with Valums Ajax File-Uploader? - Stack Overflow

programmeradmin4浏览0评论

When using Valums Ajax file uploader, how can I trigger the upload?

The default behavior is for the upload to begin immediately after the user selects a file. I want to prevent this from happening, and instead trigger the upload when the user clicks a separate "Upload" button after they have selected a file.

I looked through the code and found that the upload begins on the change event attached to the file input. I began by adding return false; to to the onSubmit function, and then attaching a click event to another button that triggered the change event:

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

That doesn't work. It just opens the file menu again.

How can I prevent the upload from occurring immediately after the user selects the file and instead trigger it when the user clicks another button?

When using Valums Ajax file uploader, how can I trigger the upload?

The default behavior is for the upload to begin immediately after the user selects a file. I want to prevent this from happening, and instead trigger the upload when the user clicks a separate "Upload" button after they have selected a file.

I looked through the code and found that the upload begins on the change event attached to the file input. I began by adding return false; to to the onSubmit function, and then attaching a click event to another button that triggered the change event:

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

That doesn't work. It just opens the file menu again.

How can I prevent the upload from occurring immediately after the user selects the file and instead trigger it when the user clicks another button?

Share Improve this question asked Jun 5, 2012 at 3:48 user1091949user1091949 1,9334 gold badges21 silver badges27 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You will have to modify the file-uploader.js file for this. In line 309, modify the onChange function to return false. Then add the following function above it, so that the code bees:

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, within your button click or any other event, call

uploader.startUpload();

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

Hope that helps :)

Valums Ajax file uploader now supports this feature.. You can Queue Files and Trigger Upload on Button Click

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

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

For more on this, check out this link : valums file uploder

发布评论

评论列表(0)

  1. 暂无评论