【问题标题】:Python Firebase How to check whether a file exists on firebase storagePython Firebase如何检查文件是否存在于firebase存储中
【发布时间】:2021-02-26 11:02:57
【问题描述】:

您好,我想知道是否可以使用 python 检查文件是否存在于 firebase 存储中。以下是针对其他语言的几种方法。

How to check if a file exists in Firebase storage from your android application?

how to check if file exists in Firebase Storage?

python的等效方法是什么。

【问题讨论】:

标签: 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 模块

【讨论】:

    猜你喜欢
    • 2016-10-11
    • 1970-01-01
    • 2017-08-10
    • 2016-11-06
    • 2022-01-24
    • 1970-01-01
    • 2022-08-21
    • 2017-09-19
    • 2019-01-04
    相关资源
    最近更新 更多