【发布时间】:2020-12-16 10:54:30
【问题描述】:
我正在使用免费的 Firebase 存储计划。当我想从 Python 中存储图片时,它可以正常工作:
import os
import firebase_admin
from firebase_admin import credentials, storage
file_extension = os.path.splitext(request.files["input_image"].filename)[1] # ex: jpg
cred = credentials.Certificate(os.getenv("FIREBASE_CREDS"))
firebase_admin.initialize_app(cred)
bucket = storage.bucket(os.getenv("FIREBASE_BUCKET"))
# ex: profile_pictures/user1.jpg
blob = bucket.blob(f"profile_pictures/{current_user.username}{file_extension}")
blob.upload_from_string(request.files["input_image"].filename)
profile_picture_url = blob.public_url
但是,当我尝试访问图片公共 url 时,我看到了这个页面,而我期待的是一张图片:
链接如下:
https://storage.googleapis.com/bucket_name/folder_name/filename
请注意,我的规则策略如下:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write;
}
}
}
【问题讨论】:
-
您使用的是 Python 的 Admin SDK,它完全绕过了 Firebase 安全规则。结合
google-cloud-storage:stackoverflow.com/… 搜索错误消息可能会更好。
标签: python firebase firebase-storage