首页 > 解决方案 > Firebase 存储大小限制未强制执行

问题描述

您好,我对文件夹 /posts/media/{userId}/{media} 有如下规则:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPath=**} {
      allow read, create, write;
    }

    match /posts/media {
        allow create: if request.auth != null && request.resource.size < 10 * 1024 * 1024
                   && request.resource.contentType.matches('(image|video)/.*');

      match /{userId}/{allPaths=**} {
        allow create, write: if request.auth.uid == userId && request.resource.size < 10 * 1024 * 1024
                   && request.resource.contentType.matches('(image|video)/.*');
      }
    }
  }
}

不强制使用 10MB 的文件大小。用户可以轻松发布数倍于 10MB 限制的视频。

有什么帮助吗?

谢谢你,米歇尔

标签: firebasefirebase-storagefirebase-security

解决方案


此规则允许对整个存储桶进行不受限制的读写访问:

match /{allPath=**} {
  allow read, create, write;
}

如果您不想要这种行为,请删除该规则。它的许可性将凌驾于所有其他规则之上。您不能缩小其他规则授予的访问范围。如果任何规则允许访问文件,则不能被其他规则更改。


推荐阅读