Boto s3 get_metadata

2019-04-20 11:28发布

问题:

Trying to get meta_data that i have set on all my items in an s3 bucket. Which can be seen in the screenshot and below is the code I'm using. The two get_metadata calls return None. Any idea's

boto.Version '2.5.2'

amazon_connection = S3Connection(ec2_key, ec2_secret)
  bucket = amazon_connection.get_bucket('test')
  for key in bucket.list():
    print " Key %s " % (key)
    print key.get_metadata("company")
    print key.get_metadata("x-amz-meta-company")

回答1:

bucket.list() does not return metadata. try this instead:

for key in bucket.list():
   akey = bucket.get_key(key.name)
   print akey.get_metadata("company")