我正在尝试从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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句