0

when i am trying to upload a video file to cloudinary and restrict the file size to 20mb it is not working properly. How to apply the condition for file size restriction ? Below is my javascript code and html code

$(document).ready(function() {
  $('.progress').hide();
  $('#cloudinary_response').hide();
});

$('#upload_file').bind('change', function() {
  var file_size = this.files[0].size;
  if (file_size < 200000) {
    $('#upload_file').unsigned_cloudinary_upload('xyz', {
      cloud_name: 'xyz',
      tags: 'upload'
    }).bind('cloudinarydone', function(e, data) {
      public_id = data.result.public_id;


    }).bind('cloudinarystart', function(e, data) {
      $('.progress').show();
      transform = {
        cloud_name: 'xyz'
      };
    }).bind('cloudinaryprogress', function(e, data) {
      $('.progress-bar').css('width',
        Math.round((data.loaded * 100.0) / data.total) + '%')
    });
  } else {
    alert("File size is greater than 20MB")
  }
});
<form>
  <input name="file" type="file" id="upload_file" accept="video/mp4,video/x-m4v,video/*">
  <input type="text" name="cloudinary_response" id="cloudinary_response">
</form>
Gagan Sharma
  • 262
  • 1
  • 4
  • 21

1 Answers1

0

Restricting video size is available as a built-in feature. All you have to do is set the maxFileSize parameter as demonstrated here:

https://github.com/cloudinary/cloudinary_js#client-side-image-resizing-before-upload

Make sure to import the required JS files (in the right order), as mentioned in the docs.

Nadav Ofir
  • 778
  • 4
  • 6