0

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.

1 Answer 1

2

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
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.