我正在尝试获取一个文件的URL,我要上传到Firebase存储。我想要在末尾包含令牌的URL,看起来像这样的那个:https://firebasestorage.googleapis.com/v0/b/myapp.appspot.com/o/folder%myfile?alt=media&token=mytoken
到目前为止这是我的代码:
from firebase_admin import credentials, initialize_app
cred = credentials.Certificate("serviceAccountKey.json")
initialize_app(cred, {'storageBucket': 'myapp.appspot.com'})
bucket = storage.bucket()
path = "path/to/myfile"
blob = self.bucket.blob(path)
blob.upload_from_filename("temp.mp3")
# I only know how to get this URL but it's not the one that I want
blob.make_public()
url = blob.public_url
我也不想让签名的URL过期。
我见过人们提到函数getDownloadURL
,但我不知道如何在Python中使用firebase-admin。
我检查了https://googleapis.dev/python/storage/latest/blobs.html,但是我所能找到的关于URL的只有signedURL或publicURL
发布于 2022-08-17 22:44:19
将安全规则更改为该特定文件夹
确保您将公开可见的图像上载到特定的文件夹images
Client SDK
完成,并且在Admin SDK
for firebase-admin
python中不可用
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
// Explicitly define rules for the 'path/to/myfile/' pattern
match /path/to/myfile/{allPaths}{
allow write: if request.auth != null; // Only Auth person can read
allow read: if request.auth == null; // Anyone can read
}
// This will be defined for everything else
match /{allPaths=**} {
allow write: if request.auth != null; // Only auth person can write
allow read: if request.auth != null; // Only auth person can read
}
}
}
示例python代码
storageBucket='myapp.appspot.com'
bucket_path="path/to/myfile/temp.mp3"
firebase_storageURL = 'https://firebasestorage.googleapis.com/v0/b/{}/o/{}?alt=media'.format(storageBucket, bucket_path)
https://stackoverflow.com/questions/72037182
复制相似问题