【问题标题】:Python Firebase How to check whether a file exists on firebase storagePython Firebase如何检查文件是否存在于firebase存储中
【发布时间】:2021-02-26 11:02:57
【问题描述】:
【问题讨论】:
标签:
python
firebase
google-cloud-storage
firebase-storage
【解决方案1】:
我能够使用请求模块并使用文件的公共 url 让它工作。希望这可以帮助其他面临同样问题的人。
import requests
from firebase_admin import storage
#Creates the blob reference to file on the server
bucket = storage.bucket()
blob = bucket.blob("firebase/path/to/file")
#Requests the file using the public url
r = requests.head(blob.public_url)
#Whether the file exists or not on the server
fileExists = (r.status_code == requests.codes.ok)
编辑
感谢您可以使用的一些有用的指针
fileExists = blob.exists()
这意味着您不再需要 requests 模块