0

The default jquery-file-upload function does not have any validation before uploading files.

I want to restrict the upload to only a pdf file.

I found jquery.fileupload-validate.js file in the js folder, but I do not know how to modify this file.

Please help me. i found this lines in jquery-file-upload $.blueimp.fileupload.prototype.options.processQueue.push( { action: 'validate', // Always trigger this action, // even if the previous action was rejected: always: true, // Options taken from the global options map: acceptFileTypes: '@', maxFileSize: '@', minFileSize: '@', maxNumberOfFiles: '@', disabled: '@disableValidation' } but i do not know how to change it.

  • Be sure to validate the file for security on the server side as well - it's easy for a malicious user to bypass client-side checks. – joews Oct 29 '13 at 20:27
  • If checking the extension isn't enough, using [HTML5 FileReader](https://developer.mozilla.org/en-US/docs/Web/API/FileReader) may help as well. – Dan Goodspeed Oct 29 '13 at 20:30
  • I validate file type in server side.but i want validate file type on client side. – user180999 Oct 29 '13 at 20:35

2 Answers2

1

In your js file where you validate your form or only file upload use like

<script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>

jQuery.validator.setDefaults({
  debug: true,
  success: "valid"
  });
  $("#form").validate({
    rules:
      'image': {
        required: true
        accept: "application/pdf"
      }
   }, 
    messages: {
      "image": {
        required: "Please upload only pdf files."
      }
    },
    submitHandler: function(form) {
    form.submit();
    }
  });
});
LHH
  • 3,233
  • 1
  • 20
  • 27
  • i found this lines in jquery-file-upload ` $.blueimp.fileupload.prototype.options.processQueue.push( { action: 'validate', // Always trigger this action, // even if the previous action was rejected: always: true, // Options taken from the global options map: acceptFileTypes: '@', maxFileSize: '@', minFileSize: '@', maxNumberOfFiles: '@', disabled: '@disableValidation' }` but i do not know how to change it. – user180999 Oct 29 '13 at 21:25
  • you do not need to change nay code in yourblueimp javascript file..just put validation where you call your file upload function – LHH Oct 29 '13 at 21:30
  • check this link for more info http://forum.jquery.com/topic/jquery-beginner-using-blueimp-fileupload-plugin – LHH Oct 29 '13 at 21:31
0

You accept method for validate file upload in jquery like

accept= "application/pdf"

hope this link will help yoo http://jqueryvalidation.org/accept-method/

LHH
  • 3,233
  • 1
  • 20
  • 27