dropzone.js图片上传acceptedMimeTypes [英] dropzone.js image upload acceptedMimeTypes
问题描述
我使用dropzone.js插件将图像上传器添加到我的应用程序中。我知道这可能是一个非常基本的问题,所以我想要做的是限制文件扩展名。这适用于单个文件扩展名,
< script type =text / javascript>
Dropzone.options.dropzone = {
accept:function(file,done){
console.log(file);
if(file.type!=image / jpeg){
done(Error!This type of files are not accepted);
}
else {done(); }
}
}
< / script>
所以我的问题是如何添加多个文件扩展名,即 image / jpeg ,
image / png
?
谢谢
<您可以添加更多的扩展到如果
,如下所示:
if(file.type!=image / jpeg&& file.type!=image / png){
这将检查文件类型是否与您指定的所有类型不同。对于通过支票的文件,它必须与image / jpeg和image / png不同
更新
我建议查看 enyo的答案,因为他是Dropzone的作者。 / p>
I am using the dropzone.js plugin to add an image uploader to my application. I know this is probably a really basic question so apologies but what I want to do is limit the file extensions. This works for a single file extension,
<script type="text/javascript">
Dropzone.options.dropzone = {
accept: function(file, done) {
console.log(file);
if (file.type != "image/jpeg") {
done("Error! Files of this type are not accepted");
}
else { done(); }
}
}
</script>
So my question is how to add multiple file extensions, i.e. image/jpeg
, image/png
?
Thanks
You could add more extensions to your if
, like so:
if (file.type != "image/jpeg" && file.type != "image/png") {
This will check if the file type is different from ALL of the types you specify. For a file to pass the check, it has to be different from image/jpeg AND image/png
Update
I would advise to look at enyo's answer since he is the author of Dropzone.
这篇关于dropzone.js图片上传acceptedMimeTypes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!