简体   繁体   中英

Restrict the file type and total size of files uploded using drag and drop option of jquery fileupload plugin

I am new to Jquery and I am using blueimp jquery.fileupload plugin to upload files . In my application there is restriction for only certain type of file like .class, .java etc.

so how to specify to restrict only certain type of files and allow all the other types of file to upload ? also i have to specify the maximum size of all the files getting uploded not individual size but the sum of sizes of all the file should be restricted.

I have implemented these two things for add file button in that plugin.but i am not able to implement this with drag and drop option provided in that plugin.

Code is like :

$('#fileupload').fileupload('option', {
            disableImageResize: false,
            maxFileSize: 5000000,
            acceptFileTypes: /(\.|\/)(gif|jpe?g|png|txt)$/i
  });

So it is like max size for each item and file types which are accepted. I want to specify the type to be restricted and maximum size of all files tobe restricted

First of all, not all browsers support files size restriction - some only support names and not any additional data.

Now, to the question at hand - use the callbacks the plugin provides.

$('#fileupload').fileupload('option', {
        add: function (e, result) { 
            // Here you can access properties like:
            // var type = result.files[0].type;
            // var size = result.files[0].size;
            // and so on........            
        }
});

You should check the callbacks API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM