Nervgh Angular File Upload - 如何限制文件格式说jpeg和png? [英] Nervgh Angular File Upload - How do I restrict the file formats to say jpeg and png?
本文介绍了Nervgh Angular File Upload - 如何限制文件格式说jpeg和png?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
您想要使用文档。
创建过滤器:
var uploader = $ scope.uploader = new FileUploader({
url:'/ api / users / photo'
});
$ b // FILTERS
uploader.filters.push({
name:'imageFilter',
fn:function(item / * {File | FileLikeObject} * /,options){
var type ='|'+ item.type.slice(item.type.lastIndexOf('/')+ 1)+'|';
return'| jpg | png | jpeg | bmp | gif |'.indexOf(type)!== -1;
}
});
文档建议在HTML中输入它,例如我在下面完成:
< input type =filenv-file-select =uploader =uploaderfilters =imageFilter>
这段代码被用在他的示例网站,允许图片只上传。
I am upgrading an application that is using nv-file-select directive. I am unsure as to how to restrict the file formats supported for upload.
解决方案
You want to use the filters as described in the documentation.
Create the filter:
var uploader = $scope.uploader = new FileUploader({
url: '/api/users/photo'
});
// FILTERS
uploader.filters.push({
name: 'imageFilter',
fn: function(item /*{File|FileLikeObject}*/, options) {
var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
}
});
Docs suggests entering it in the HTML, such as I have done below:
<input type="file" nv-file-select="" uploader="uploader" filters="imageFilter">
This code was used on his sample site that allows for image only uploads.
这篇关于Nervgh Angular File Upload - 如何限制文件格式说jpeg和png?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文