如何将文件中的S3存储桶使用博托上传到目录 [英] how to upload a file to directory in S3 bucket using boto

查看:129
本文介绍了如何将文件中的S3存储桶使用博托上传到目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Python来复制文件在S3存储桶。 例如:我有水桶的名字=测试。而在桶桶中,我有2个文件夹的名称为垃圾和放大器; 输入。现在,我想复制使用python..Can本地目录S3转储文件夹中的文件,任何一个能帮助我吗?

I want to copy a file in s3 bucket using python. Ex : I have bucket name = test. And in bucket the bucket, I have 2 folders name "dump" & "input". Now I want to copy a file from local directory to S3 "dump" folder using python..Can any one help me?

推荐答案

试试这个...

import boto

AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''

bucket_name = AWS_ACCESS_KEY_ID.lower() + '-dump'
conn = boto.connect_s3(AWS_ACCESS_KEY_ID,
        AWS_SECRET_ACCESS_KEY)


import boto.s3
bucket = conn.create_bucket(bucket_name,
    location=boto.s3.connection.Location.DEFAULT)

testfile = "replace this with an actual filename"
print 'Uploading %s to Amazon S3 bucket %s' % \
   (testfile, bucket_name)

import sys
def percent_cb(complete, total):
    sys.stdout.write('.')
    sys.stdout.flush()

from boto.s3.key import Key
k = Key(bucket)
k.key = 'my test file'
k.set_contents_from_filename(testfile,
    cb=percent_cb, num_cb=10)

这篇关于如何将文件中的S3存储桶使用博托上传到目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆