Skip to content Skip to sidebar Skip to footer

Restrict Filetype ,size,single Upload Doesn't Work In Jquery File Upload

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 excel(x

Solution 1:

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');
                                    }
                                },

Post a Comment for "Restrict Filetype ,size,single Upload Doesn't Work In Jquery File Upload"