如何将多个文件上传到 AWS S3?
我尝试了两种方法,但都失败了:
1)s3cmd 显示以下错误,即使文件只有 270KB。
$s3cmd put file_2012_07_05_aa.gz s3://file.s3.oregon/
file_2012_07_05_aa.gz -> s3://file.s3.oregon/file_2012_07_05_aa.gz [1 of 1]
45056 of 272006 16% in 1s 25.62 kB/s failed
WARNING: Upload failed: /file_2012_07_05_aa.gz ([Errno 32] Broken pipe)
WARNING: Retrying on lower speed (throttle=0.00)
WARNING: Waiting 3 sec...
2)使用boto的S3接口。
仅当我使用“美国标准”创建存储桶时,boto 库才对我正常工作,如果我选择俄勒冈等其他地区,它将失败并显示“对等方重置连接”
def connect_to_s3(access_key, secret_key):
conn = S3Connection(access_key, secret_key)
return conn
def percent_cb(complete, total):
sys.stdout.write('.')
sys.stdout.flush()
def upload_to_s3(bucket, file_name):
key = bucket.new_key(file_name)
key.set_contents_from_filename(file_name,cb=percent_cb, num_cb=10)