带有list_blobs_with_prefix()前缀参数的正则表达式

问题描述 投票:0回答:1

我正在尝试使用python api客户端从gcp存储中获取带前缀的对象,但前缀参数出现问题。我可以使用[]在gsutil中进行操作

gsutil ls -h gs://{{bucket-name}}/*/latest/

但不是使用python api

我正在使用文档中的功能。尝试将前缀参数传递为

*/latest//*/latest*

并将定界符设置为none。仍然没有任何结果。

    storage_client = storage.Client()

    # Note: Client.list_blobs requires at least package version 1.17.0.
    blobs = storage_client.list_blobs(bucket_name, prefix=prefix,
                                      delimiter=delimiter)

    print('Blobs:')
    for blob in blobs:
        print(blob.name)

    if delimiter:
        print('Prefixes:')
        for prefix in blobs.prefixes:
            print(prefix)

预期输出是

gs://{{bucket-name}}/product/latest/:
gs://{{bucket-name}}/product/latest/health
gs://{{bucket-name}}/product/latest/index.html

我正在尝试使用python api客户端从gcp存储中获取带前缀的对象,但前缀参数出现问题。我可以在gsutil中使用gsutil ls -h gs:// {{bucket-name}} / * / latest / ...

google-cloud-storage google-api-python-client
1个回答
0
投票

gsutil知道正则表达式,但是GCS API本身不知道。这些API仅支持文字前缀。

© www.soinside.com 2019 - 2024. All rights reserved.