我在文档中找不到使用直接上传时如何限制文件大小。我正在使用以下方法在服务器端生成文件上传输入字段:
cloudinary.uploader.image_upload_tag
然后从客户端上传文件。
还。$cloudinary.config 似乎是为指定 api 密钥和存储桶名称而设计的,没有其他配置。
我很感激这方面的任何启示!
我在文档中找不到使用直接上传时如何限制文件大小。我正在使用以下方法在服务器端生成文件上传输入字段:
cloudinary.uploader.image_upload_tag
然后从客户端上传文件。
还。$cloudinary.config 似乎是为指定 api 密钥和存储桶名称而设计的,没有其他配置。
我很感激这方面的任何启示!
如果您使用直接上传,请在直接上传 javascript 中修复您的最大可上传文件大小,这是代码示例。
$(function () {
$('#direct_upload input[type="file"]')
.fileupload({
dropZone: '#direct_upload',
disableImageResize: true,
imageMaxWidth: 600,
imageMaxHeight: 600,
maxFileSize:2048 //2 mb
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
start: function () {
$("#direct_upload .progress").attr("style","display:block")
},
progress: function (e, data) {
var com = Math.round((data.loaded * 100.0) / data.total)
$("#direct_upload .progress .progress-bar").attr("style","width:"+com+"%")
$("#direct_upload .progress .progress-bar").text(com +"% Complete")
},
})
.on('cloudinarydone', function (e, data) {
$('#submit-btn').attr('style','');
$("#direct_upload .progress").attr("style","display:none")
$("#direct_upload .progress .progress-bar").attr("style","width:0%")
$("#direct_upload .progress .progress-bar").text("0% Complete")
$.post(this.form.action, $(this.form).serialize()).always(function (result, status, jqxhr) {
$('.status_value').text(result.errors ? JSON.stringify(result.errors) : status);
});
var image_url = $.cloudinary.image(data.result.public_id, {
format: data.result.format, width: 75, height: 75,style: "display:none", crop: "fill"
})
$('.Submitted').append(image_url);
});
});
希望这对你有用。
maxFileSize:2048
这会将您的文件大小最大固定为 2 mb。