boto3 get_object(...) 是否立即下载 python 中的实际文件?

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

背景:

根据 boto3

get_object()
文档,方法
get_object(**kwargs)
具有以下响应签名:

{
    'Body': StreamingBody(),
    'DeleteMarker': True|False,
    'AcceptRanges': 'string',
    'Expiration': 'string',
    'Restore': 'string',
    'LastModified': datetime(2015, 1, 1),
    'ContentLength': 123,
    'ETag': 'string',
    'MissingMeta': 123,
    'VersionId': 'string',
    'CacheControl': 'string',
    'ContentDisposition': 'string',
    'ContentEncoding': 'string',
    'ContentLanguage': 'string',
    'ContentRange': 'string',
    'ContentType': 'string',
    'Expires': datetime(2015, 1, 1),
    'WebsiteRedirectLocation': 'string',
    'ServerSideEncryption': 'AES256'|'aws:kms',
    'Metadata': {
        'string': 'string'
    },
    'SSECustomerAlgorithm': 'string',
    'SSECustomerKeyMD5': 'string',
    'SSEKMSKeyId': 'string',
    'StorageClass': 'STANDARD'|'REDUCED_REDUNDANCY'|'STANDARD_IA'|'ONEZONE_IA'|'INTELLIGENT_TIERING'|'GLACIER'|'DEEP_ARCHIVE',
    'RequestCharged': 'requester',
    'ReplicationStatus': 'COMPLETE'|'PENDING'|'FAILED'|'REPLICA',
    'PartsCount': 123,
    'TagCount': 123,
    'ObjectLockMode': 'GOVERNANCE'|'COMPLIANCE',
    'ObjectLockRetainUntilDate': datetime(2015, 1, 1),
    'ObjectLockLegalHoldStatus': 'ON'|'OFF'
}

问题:

目前,我只需要

Metadata
字段中包含的数据。但我想确保我不会因为下载
Body
的内容而产生不必要的费用。

boto3
是立即下载
Body
的内容还是等到我打电话给
response["Body"].read()

python amazon-web-services amazon-s3 boto3
1个回答
1
投票

如果您只想要对象的元数据,请使用

head_object()
:

HEAD 操作从对象中检索元数据,而不返回对象本身。如果您只对对象的元数据感兴趣,则此操作非常有用。要使用 HEAD,您必须具有对该对象的 READ 访问权限。

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