作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试从 Firebase 存储中下载一些文件。现在我正在尝试列出特定路径中的所有文件,如下所示:
from google.cloud import storage
client = storage.Client()
bucket = client.get_bucket('myapp.appspot.com/path/to/folder')
blob = list(bucket.list_blobs())
print(len(blob))
我看到的问题是,我正在获取存储桶中的所有结果,而我只需要我选择的路径中的结果。
我做错了什么?还有其他方法可以实现我的需要吗?
感谢您的帮助。
最佳答案
你应该试试:
from google.cloud import storage
from google.cloud.storage import Blob
storage_client = storage.Client()
# get all the buckets
buckets = storage_client.list_buckets()
for bucket in buckets:
print(bucket.name)
# output bucket_name
# get all the blobs in a bucket
bucket = client.get_bucket("bucket_name")
blobs = list(bucket.list_blobs())
for blob in blobs:
print (blob)
# print the blobs: blob_name
#check if the blob exists
assert isinstance(bucket.get_blob('blob_name'), Blob)
#get the blob from path
my_blob = Blob.from_string("gs://bucket_name/blob_name")
# List the files in a folder
files = bucket.list_blobs(prefix='folder_name')
for f in files:
print(f.name)
关于python-3.x - 如何从 Firebase 存储下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58673023/
我是一名优秀的程序员,十分优秀!