我目前正在使用此代码:
#!/usr/bin/env python
import boto
import boto.s3
from boto.s3.key import Key
AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''
filename = 'test.zip'
bucket_name = AWS_ACCESS_KEY_ID.lower() + '-mah-bucket'
conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
bucket = conn.create_bucket(bucket_name, location=boto.s3.connection.Location.DEFAULT)
k = Key(bucket)
k.key = 'my test file'
k.set_contents_from_filename(filename)
我有两个问题。首先,我相信这段代码会创建一个存储桶并进行上传。事情是我不想创建一个桶,因为我已经有了一个。为了做到这一点,我只需将其更改为:
k = Key(bucket_name)
并摆脱这个:
bucket = conn.create_bucket(bucket_name, location=boto.s3.connection.Location.DEFAULT)