Giuseppe Lodi Rizzini
Giuseppe Lodi Rizzini

Reputation: 1055

Krajee file input check mime type of selected file

I'd like to show an alert if I select a file .zip or .rar by mime type (not extension).

But i don't know what's the exact, if exist, method of this plugin.

$("#file").fileinput({
                    'language': 'it',
                    maxFileCount: 1,
                    'showPreview':true,
                    'removeFromPreviewOnError': true,
                    'showUpload':false,
                    maxFileSize: 25600,
                    allowedFileExtensions: ["jpg", "gif", "png", "zip", "rar", "pdf", "doc", "docx", "xls", "xlsx"]
                }).on('fileselect', function(event, numFiles, label) {

                    // check mime type for zip or rar ?? how ??

                    if ( mime == "zip" || mime == "rar" ) {

                    alert(label + " is an archive file");

                    }
                });

Upvotes: 0

Views: 257

Answers (2)

kravisingh
kravisingh

Reputation: 1670

You can use Content-Type and assign the proper value for it's type.

if(Content-Type == application/x-rar-compressed || Content-Type == 
 application/octet-stream || Content-Type == application/zip){
    alert(label + " is an archive file");
}

For more MIME types visit this link: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types

Upvotes: 1

Giuseppe Lodi Rizzini
Giuseppe Lodi Rizzini

Reputation: 1055

Found solution:

.on('fileselect', function(event, numFiles, label) {

     alert(event.currentTarget.files[0].type);

});

Upvotes: 0

Related Questions