Jquery file upload plugin: how to validate files on add?

后端 未结 6 2210
予麋鹿
予麋鹿 2020-12-13 15:47
$(\'#fileupload\')
    .fileupload({
        acceptFileTypes: /(\\.|\\/)(jpg)$/i
    })
    .on(\'fileuploadadd\', function (e, data) {
        console.log(data.file         


        
6条回答
  •  余生分开走
    2020-12-13 16:29

    Here is what you want to do:

    $('#fileupload')
        .fileupload({
            acceptFileTypes: /(\.|\/)(jpg)$/i
        })
        .bind('fileuploadadded', function (e, data) {
            console.log(data.files.valid);
        });
    

    The core jquery.fileupload.js file is adding your files and triggering the "fileuploadadd" event, but that's before the files are validated.

    The file jquery.fileupload-ui.js is doing the validation after the files are added, and triggering another "fileuploadadded" event once that's done.

    Change the event, and you're all set.

    Please Note:

    This answer was valid and working as of March 2013 when it was posted. It appears that this upload plugin has changed since then. That means there is a new problem, and you should post a new question (or search to see if someone already has) rather than downvote this one!

提交回复
热议问题