How do I get the file / key size in boto S3?

后端 未结 5 1910
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 05:33

There must be an easy way to get the file size (key size) without pulling over a whole file. I can see it in the Properties of the AWS S3 browser. And I think I can get it

5条回答
  •  忘掉有多难
    2020-12-13 06:27

    in boto3:

    s3.head_object also performs a HEAD request to retrieve the meta data about the object:

    s3 = boto3.client('s3')
    response = s3.head_object(Bucket='bucketname', Key='keyname')
    size = response['ContentLength']
    

提交回复
热议问题