【问题标题】:What is the difference between boto3 list_objects and list_objects_v2?boto3 list_objects 和 list_objects_v2 有什么区别?
【发布时间】:2016-09-28 18:43:21
【问题描述】:

我正在尝试使用 boto3 在 python 中列出 Amazon s3 存储桶中的对象。

boto3 似乎有 2 个函数用于列出存储桶中的对象:list_objects()list_objects_v2()

两者之间有什么区别,使用其中一个有什么好处?

【问题讨论】:

    标签: python amazon-s3 boto3


    【解决方案1】:

    并排比较。

    list_objects():

    response = client.list_objects(
        Bucket='string',
        Delimiter='string',
        EncodingType='url',
        #Marker to list continuous page
        Marker='string',
        MaxKeys=123,
        Prefix='string'
    )
    

    list_objects_v2()

    response = client.list_objects_v2(
        Bucket='string',
        Delimiter='string',
        EncodingType='url',
        MaxKeys=123,
        Prefix='string',
        # Replace marker to list continuous page
        ContinuationToken='string',
    
        # set to True to fetch key owner info. Default is False.
        FetchOwner=True|False,
    
        # This is similar to the Marker in list_object()
        StartAfter='string'
    )
    

    添加的功能。由于每页列出 1000 个键的限制,使用标记列出多个页面可能会让人头疼。从逻辑上讲,您需要跟踪您成功处理的最后一个密钥。使用ContinuationToken,您不需要知道最后一个键,您只需在响应中检查NextContinuationToken 的存在。您可以生成并行进程来处理 1000 个键的乘法,而无需处理最后一个键来获取下一页。

    【讨论】:

    • 是的。改进了分页,调用有更多功能。
    猜你喜欢
    • 1970-01-01
    • 2015-11-26
    • 1970-01-01
    • 2022-01-06
    • 2019-06-28
    • 2010-10-02
    • 2011-12-12
    • 2010-09-16
    • 2012-03-14
    相关资源
    最近更新 更多