Firebase存储发布规则适用于删除规则 [英] Firebase Storage Post rules apply to Delete rules

查看:118
本文介绍了Firebase存储发布规则适用于删除规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的规则,适用于img dir:

This are my rules, applied to an img dir:

match /img {
  match /{fileId} {
    allow read, 
          write: if request.resource.contentType.matches('image/jpeg')
                 || request.resource.contentType.matches('image/png')
                 || request.resource.contentType.matches('image/gif')
                 && request.resource.size < 2 * 1024 * 1024
    }
  }
}

问题是这些规则也被应用于delete(),因为它也是一个写入方法,所以它总是返回一个权限错误。在这个文档中我找不到任何东西。如何从POST / PUT规则和DELETE规则推迟?

The problem is that those rules are also being applied to delete() as it is a write method too, so it always returns a permission error. I couldn't find anything in the documentation regarding this. How can I defer from POST/PUT rules and DELETE rules?

推荐答案

我自己找到解决方案。通过在没有资源发送(删除)的情况下应用规则,它也获得写入许可。

Found the solution by myself. By letting the rule to apply when there is no resource sent at all (delete), it also gets write permission. The rest of the create/update code is sent to an OR expression.

match /img {
    match /{fileId} {
        allow read, 
        write: if request.resource == null || 
            (request.resource.contentType.matches('image/jpeg')
            || request.resource.contentType.matches('image/png')
            || request.resource.contentType.matches('image/gif')
            && request.resource.size < 2 * 1024 * 1024)
    }
}

这篇关于Firebase存储发布规则适用于删除规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆