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

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


        
6条回答
  •  感情败类
    2020-12-13 16:41

    This is what you want to do with the newer version of the plugin (9.11.2): Include this files:
    - jquery.ui.widget.js
    - jquery.iframe-transport.js
    - jquery.fileupload.js
    - jquery.fileupload-process.js
    - jquery.fileupload-validate.js

    $('#fileupload')
    .fileupload({
        acceptFileTypes: /(\.|\/)(jpg)$/i
    })
    .on('fileuploadadd', function (e, data) {
        console.log('validation object not available at this point. Do not do submit here');
    })
    .on('fileuploadprocessalways', function (e, data) {
        console.log(data.files.error);//true if error
        console.log(data.files[0].error);//error message
        if(!data.files.error) data.submit(); //do submission here
    });
    

提交回复
热议问题