Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to find the size of a file while uploading in JSP?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 463
    Comment on it

    Sometimes we need to find the size of a file at the time of uploading to prevent the file that is greater than a particular size. We can achieve this by handling "change" event of a input-file.

    Examlpe: Suppose I want to upload a file less than 3 MB.

    <input type="file" name="uploadFile" id="uploadFile" class="upload" title="Choose a file to upload"> 
    <span id="fileName_error"></span>
    
    
    <script>
    $('#uploadFile').bind('change', function() {
                  handleUpload();
              });
    
    function handleUpload(){
    
              if($('#uploadFile').val() !='')
              {
                 //Get size of file
                 var size = $('#uploadFile')[0].files[0].size/1024/1024;
                 if(size > 3)
                 {
                    $('#fileName_error').text('Please upload the file less than 3MB.');
                    return false;
                 }
                $('#fileName_error').text('');
                    return true;
              }
          }
    
    </script>
    

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: