THp*_*ubs 3 javascript jquery file-upload dropzone.js
Let's say I need to restrict my users from uploading images below 3MP (Nearly 2048px wide). How can I do this in Dropzone.js? Tried to do it with 'accept' but it's not working :
$(function() {
var mediaDropzone;
mediaDropzone = new Dropzone("#media-dropzone", {
paramName: "file",
autoProcessQueue: false,
parallelUploads: 500,
maxFilesize: <%= ENV["max_image_size"] %>,
acceptedFiles: '<%= ENV["accepted_files"] %>',
accept: function(file, done) {
if (file.width < 2048) {
done("Naha, you don't.");
}
else { done(); }
}
});
Run Code Online (Sandbox Code Playgroud)
小智 5
我有类似的需求,并且正在使用此解决方案:
var maxImageWidth = 1000, maxImageHeight = 1000;
Dropzone.options.dropzonePhotographs = {
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 2, // MB
dictDefaultMessage: "Drag files or click here",
acceptedFiles: ".jpeg,.jpg,.png,.gif",
init: function () {
this.on("success", function(file, responseText) {
file.previewTemplate.setAttribute('id',responseText[0].id);
});
this.on("thumbnail", function(file) {
if (file.width > maxImageWidth || file.height > maxImageHeight) {
file.rejectDimensions()
}
else {
file.acceptDimensions();
}
});
},
accept: function(file, done) {
file.acceptDimensions = done;
file.rejectDimensions = function() { done("Image width or height too big."); };
}
};
Run Code Online (Sandbox Code Playgroud)
您可以在此处找到原始解决方案:https : //github.com/enyo/dropzone/issues/708
| 归档时间: |
|
| 查看次数: |
5803 次 |
| 最近记录: |