我正在使用 CollectionFS 包通过我的流星应用程序上传图像,但无法使用 验证文件filters
,到目前为止,我可以上传任何扩展名和任何大小的任何文件。
模板
<template name="uploadPicture">
<label class="ui primary left labeled icon button" for="file" id="upload-div">
<i class="photo icon"></i>
Update Picture
<input type="file" id="file" class="myFileInput"/>
</label>
</template>
客户端/upload_picture.js
Template.uploadPicture.events({
'change .myFileInput': function (event) {
FS.Utility.eachFile(event, function(file) {
Images.insert(file, function (err, fileObj) {
// Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
});
});
}
});
lib/collection/images.js 是
Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images")],
filters: {
maxSize: 1048576, // in bytes
allow: {
contentTypes: ['image/*'],
extensions: ['png','jpg','jpeg','gif']
},
onInvalid: function (message) {
if (Meteor.isClient) {
alert(message);
} else {
console.log(message);
}
}
}
});
Images.allow({
'insert': function () {
// add custom authentication code here
return true;
}
});