Restrict filetype ,size,single upload doesn't work in jquery file upload

后端 未结 1 1253
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-12 07:50

I am trying to use the blueimp jquery file upload plugin with Spring MVC to upload the excel files.The files are getting uploaded. I would like to restrict the file type to

相关标签:
1条回答
  • 2020-12-12 08:13

    I found the solution myself for some reason the following attributes doesnt work on Basic Jquery Blueimp file upload

    maxFileSize : 50000,//this doesnt work
    acceptFileTypes : /(\.|\/)(xls|xlsx)$/i, //this doesnt work 
    singleFileUploads : true,
    maxNumberOfFiles : 1,
    

    so I had to use the add: callback as mentioned in my question but with little changes to the callback above I got it working.Here is the new callback:

    add : function(e, data) {
                                        var uploadErrors = [];
                                        if (!(/(\.|\/)(xls|xlsx)$/i)
                                                .test(data.files[0].name)) {
                                            uploadErrors
                                                    .push('Not an accepted file type');
                                        }
                                        if (data.files[0].size > 5000000) {
                                            uploadErrors
                                                    .push('Filesize is too big');
                                        }
                                        if (uploadErrors.length > 0) {
                                            alert(uploadErrors.join("\n"));
                                        } else {
                                            data.submit();
                                            $('#fileupload').fileupload('disable');
                                        }
                                    },
    
    0 讨论(0)
提交回复
热议问题