【问题标题】:Don't allow deletions on Firebase storage?不允许删除 Firebase 存储?
【发布时间】:2017-09-28 12:51:45
【问题描述】:

如果我不想让用户删除存储在 Firebase 存储中的文件,我需要编写什么规则来完成此操作?

我知道对于 Firebase 数据库,我会这样做:

".write": "newData.val() != null"

但是我该如何做这个来存储呢?

【问题讨论】:

    标签: firebase firebase-security firebase-storage


    【解决方案1】:

    很确定这已经被回答了几次(以几种方式),但我见过的最简单的答案是:

    allow write: request.resource.someProperty == resource.someProperty || resource == null;
    

    someProperty 可以是哈希(如果您不想允许覆盖)或名称(如果您希望内容被新对象覆盖)。

    【讨论】:

      【解决方案2】:

      一种方法是仅在新文件的 MD5 哈希值与现有文件相同时才允许写入:

      // Allow writes if the hash of the uploaded file is the same as the existing file
      allow write: if request.resource.md5Hash == resource.md5Hash;
      

      可能有更多/更简单的方法。但这是我在https://firebase.google.com/docs/reference/security/storage/ 遇到的第一个。

      【讨论】:

      • 我认为这首先不允许写入(如果文件不存在)
      猜你喜欢
      • 2017-03-24
      • 1970-01-01
      • 2021-01-02
      • 2020-05-24
      • 2020-09-26
      • 1970-01-01
      • 2016-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多