谷歌云存储:将特定zip文件从一个存储桶移动到另一个

0 投票
1 回答
22 浏览
提问于 2025-04-12 14:10

团队,

我正在尝试在解压文件时对文件名进行参数化。但是我遇到了下面的错误。当我在'sourceFileObject'中写出完整的文件名并去掉match_glob时,它就能正常工作。

类型错误:list_blobs() 收到了一个意外的关键字参数'match_glob'

我在requirements.txt中使用的是:google-cloud-storage==2.5.0

请看我下面的示例代码:

def fileUnzip(data,content):

    """
    Decompression logic to unzip a file based on the compression format
    """
    storage_client = storage.Client('projectname')
    source_bucket = storage_client.get_bucket("bucket-1")
    output_bucket = storage_client.get_bucket("bucket-2")
    sourceFileObject = "tm*.zip"
    if ("*" in sourceFileObject ):
        prefix  = sourceFileObject.split("*")[0]
        delimiter = sourceFileObject.split("*")[-1]
        print('prefix is: ', prefix)
        print('match_glob is: ', sourceFileObject)
    blobs = source_bucket.list_blobs(match_glob=sourceFileObject)
    [blob.name for blob in blobs if '*.zip' in blob.name ]
    compressedData = io.BytesIO(blobs.download_as_string()) ```

1 个回答

0

match_glob 这个功能从 2.10 版本开始才有。如果你想解决这个问题,需要把你的依赖项升级到这个版本。

你可以查看这个链接了解更多信息:https://cloud.google.com/python/docs/reference/storage/2.10.0/google.cloud.storage.bucket.Bucket#google_cloud_storage_bucket_Bucket_list_blobs

撰写回答