2013-02-24 152 views
3

给定的资源链接,例如:直接下载文件到S3

http://www.google.com/images/srpr/logo3w.png 

有没有一种方法来下载直接巴纽S3(最好使用宝途)?如果是这样,这将如何完成?

回答

5

任何'下载到S3'隐含意味着'下载,然后上传到S3' - 无论您是手动上传还是像boto这样的脚本或库都可以。

如果使用脚本或库(boto),它会将映像下载到与其运行的系统(本地工作站或服务器)相连的文件系统,然后使用AWS密钥和库上载它到S3。

7

您可以使用urllib2来获取文件并使用响应对象使用boto将其写入S3。

from boto.s3.connection import S3Connection 
from boto.s3.key import Key 
import urllib2 

request = urllib2.Request('http://www.google.com/images/srpr/logo3w.png') 
response = urllib2.urlopen(request) 

conn = S3Connection("MYAWSID", "MYAWSSECRET") 
bucket = conn.create_bucket('MyBucket') 
k = Key(bucket) 
k.name = "logo3w" 
k.set_contents_from_string(response.read(), {'Content-Type': response.info().gettype()}) 

如果没有包,您可以使用从PIP安装它们

pip install urllib2_file 
pip install boto