简体   繁体   中英

restrict uploading file size greater than 20 mb [cloudinary api]

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> 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM