【发布时间】:2020-09-08 00:52:50
【问题描述】:
我有一个社交应用程序,用户可以将图像发送到谷歌云存储。
所以我需要只有授权用户可以发送图像,并且一个用户不能删除另一个用户图像或覆盖另一个用户图像。
我有这个规则:
service firebase.storage {
match /b/{bucket}/o {
match /images {
// Cascade read to any image type at any path
match /{allImages=**} {
allow read;
}
// Allow write files to the path "images/*", subject to the constraints:
// 1) File is less than 5MB
// 2) Content type is an image
// 3) Uploaded content type matches existing content type (if it exists)
// 4) File name (stored in imageId wildcard variable) is less than 32 characters
match /{imageId} {
allow write: if request.resource.size < 5 * 1024 * 1024
&& request.resource.contentType.matches('image/.*')
&& (resource == null || request.resource.contentType == resource.contentType)
&& imageId.size() < 32
}
}
}
}
那么我该如何添加只有授权用户可以发送图像并且他们在发送后不能删除/覆盖图像?
谢谢!
【问题讨论】:
-
用户是否有谷歌账号?
-
@guillaumeblaquiere 我使用谷歌身份验证,但仅在我的网站中使用电子邮件/密码帐户。
-
您可以让每个用户在文件的元数据中写入他们的 uid,然后在安全规则中使用该元数据来确定用户是否应该能够删除他们自己的内容。
-
@DougStevenson 哦,谢谢你的回答!我在文档中没有找到关于删除的任何内容,你知道它是否默认拒绝?例如,在我的实际情况下,如果我不更改任何内容,每个用户都将图像发送到 /images/ 任何用户都可以删除/覆盖此文件夹中的图像吗?还是默认拒绝所有人?再次感谢!
-
在规则允许之前,一切都会被默认拒绝。
标签: firebase google-cloud-storage firebase-storage firebase-security