更新时间:2023-01-06 21:20:36
这就是我所使用的.希望对您有所帮助.
This is what I use. Hope it helps.
import firebase_admin
from firebase_admin import credentials
from firebase_admin import storage
# Fetch the service account key JSON file contents
cred = credentials.Certificate("credentials.json")
# Initialize the app with a service account, granting admin privileges
app = firebase_admin.initialize_app(cred, {
'storageBucket': '<BUCKET_NAME>.appspot.com',
}, name='storage')
bucket = storage.bucket(app=app)
blob = bucket.blob("<your_blob_path>")
print(blob.generate_signed_url(datetime.timedelta(seconds=300), method='GET'))
它会生成一个公共URL (持续300秒),供您下载文件.
It generates a public URL (for 300 secs) for you to download your files.
例如,在我的情况下,我使用该URL在django网站中使用<img>
标签显示存储的图片.
For example, in my case, I use that URL to display stored pictures in my django website with <img>
tag.
此处是更有用的功能的文档.
Here is the doc for more usefull functions.