2016-11-05 155 views
0

當我試圖將視頻文件上傳到cloudinary並將文件大小限制爲20mb時,它無法正常工作。如何應用條件來限制文件大小?下面是我的javascript代碼和HTML代碼限制上傳大於20 MB的文件大小[cloudinary api]

$(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>

回答