Chintu
Chintu

Reputation: 525

how to validate file type and file size in jquery file upload

how to validate file type, file size in jquery file upload ? i am using the following code .

 $('#fileupload').fileupload({
    dataType: 'json',
    url: '/VendorReport/UploadFiles',       
    add: function (e, data) {
        data.context = $('<button/>').text('Upload')
            .appendTo($('#divUpload'))
            .click(function () {

                var ddlType = $("#ddlType").val();
                if (ddlType == '') {
                    $('#divUpload').empty();

                    ShowNotify('Please select Type...!', 'warning', 2000);
                    return false;
                }
                $('#smp').empty();
                data.context = $('<p/>').text('Uploading...').replaceAll($(this));                    
                data.submit();
            });
    },
    success: function (msg) {
        UploadCall(msg.name);
                },
    done: function (e, data) {
        data.context.text('');            
    }
});

please help me how to validate file size and file type.

Upvotes: 0

Views: 2007

Answers (1)

Adriano Leal
Adriano Leal

Reputation: 326

You could use the validation options "acceptFileTypes" and "maxFileSize" as seen on the plugin wiki here.

Anyway an example:

$('#fileupload').fileupload({
  acceptFileTypes: /(\.|\/)(mp4)$/i, //MP4
  maxFileSize: 10000000 //10 MB
});

Upvotes: 2

Related Questions