栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Google Cloud Storage + Python:是否可以在GCS的某些文件夹中列出obj?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Google Cloud Storage + Python:是否可以在GCS的某些文件夹中列出obj?

更新 :以下内容适用于Python的旧版“ Google API客户端库”,但如果您不使用该客户端,则更喜欢适用于Python的较新的“
Google Cloud Client Library”(https://googleapis.dev/python/ storage / latest
/
index.html)。对于较新的库,与以下代码等效:

from google.cloud import storageclient = storage.Client()for blob in client.list_blobs('bucketname', prefix='abc/myfolder'):  print(str(blob))

老年客户的答案如下。

您可能会发现,使用具有完整功能的Python客户端的JSON
API更容易。它具有一个列出带有前缀参数的对象的功能,您可以通过这种方式检查某个目录及其子目录:

from apiclient import discovery# Auth goes here if necessary. Create authorized http object...client = discovery.build('storage', 'v1') # add http=whatever param if authrequest = client.objects().list(    bucket="mybucket",    prefix="abc/myfolder")while request is not None:  response = request.execute()  print json.dumps(response, indent=2)  request = request.list_next(request, response)

列表调用的完整文档在这里:https://developers.google.com/storage/docs/json_api/v1/objects/list

此处记录了Google Python API客户端:https : //pre.google.com/p/google-api-python-
client/



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/611094.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号