首页 > 解决方案 > 流星集合 fs 禁止上传

问题描述

我想在特殊情况下禁止上传/存储文件。

我在钩子之前尝试了collectionfs:

Attachments.files.before.insert((userId, doc) => {
  if(!Meteor.isServer){
    if (!isUploadAllowed()) {
      throw new Meteor.Error('Upload not allowed');
    }
  }
}

不幸的是,这不起作用。

有没有更好的方法来实现这一目标?或者有人可以帮助我吗?

(一个丑陋的解决方案是在 after.insert 钩子中删除上传的文档,我希望有更好的方法)

标签: javascriptnode.jsmongodbmeteorcollectionfs

解决方案


您可以将所有客户端操作的此集合的拒绝设置为 false:

const Attachments.files = new Mongo.Collection('fs.files')
Attachments.files.deny({
  insert () { return true },
  update () { return true },
  remove () { return true }
})

这默认拒绝任何客户端操作与服务器同步。


推荐阅读