且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

限制文件类型,大小,单个上载在jquery文件上传时不起作用

更新时间:2023-10-17 17:27:46

我出于某种原因自行找到了解决方案以下属性不适用于基本Jquery Blueimp文件上传

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,

所以我不得不使用我的问题中提到的 add:回调,但上面的回调几乎没有变化,我得到了它的工作。这是新的回调:

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