javascript - 流星集合 fs 禁止上传
问题描述
我想在特殊情况下禁止上传/存储文件。
我在钩子之前尝试了collectionfs:
Attachments.files.before.insert((userId, doc) => {
if(!Meteor.isServer){
if (!isUploadAllowed()) {
throw new Meteor.Error('Upload not allowed');
}
}
}
不幸的是,这不起作用。
有没有更好的方法来实现这一目标?或者有人可以帮助我吗?
(一个丑陋的解决方案是在 after.insert 钩子中删除上传的文档,我希望有更好的方法)
解决方案
您可以将所有客户端操作的此集合的拒绝设置为 false:
const Attachments.files = new Mongo.Collection('fs.files')
Attachments.files.deny({
insert () { return true },
update () { return true },
remove () { return true }
})
这默认拒绝任何客户端操作与服务器同步。
推荐阅读
- ios - 如何在 SwiftUI 的 ScrollView 中制作动画?SwiftUI 中的手风琴风格动画
- javascript - 如何修复“一个关闭按钮关闭所有模态”
- typescript - 为所有其他下拉菜单禁用一个下拉菜单的选定选项
- xamarin.android - 如何摆脱 Xamarin Android 上的这个资源 id 错误?
- javascript - 无服务器无法导入模块“处理程序”错误
- arduino - arduino 系统范围配置文件上的 Ardupilot 编译错误是“ArduPilot-Arduino-1.0.3-windows\hardware/tools/avr/etc/avrdude.conf”
- c++ - 在第二个监视器中显示图像的 C++ 列表屏幕
- c# - MailSystem.Net 有没有办法检查电子邮件的状态(是已读还是未读)?
- c# - 从winform中的子用户控件调用位于父用户控件中的函数
- optimizely - 优化账号注册