直接将文件下载到S3

Dav*_*542 3 python amazon-s3 boto

给定资源链接,例如:

http://www.google.com/images/srpr/logo3w.png
Run Code Online (Sandbox Code Playgroud)

有没有办法将png直接下载到S3(最好使用Boto)?如果是这样,怎么办呢?

小智 9

您可以使用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()})
Run Code Online (Sandbox Code Playgroud)

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

pip install urllib2_file
pip install boto
Run Code Online (Sandbox Code Playgroud)


Akb*_*hry 6

任何"下载到S3"都隐含地意味着"下载然后上传到S3" - 无论是手动上传还是像boto这样的脚本或库.

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