![](/img/trans.png)
[英]download svs file on s3 directly to RAM in AWS Lambda or open without local download
[英]Download a file directly to S3
給定資源鏈接,例如:
http://www.google.com/images/srpr/logo3w.png
有沒有辦法將png直接下載到S3(最好使用Boto)? 如果是這樣,怎么辦呢?
您可以使用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安裝它們
pip install urllib2_file
pip install boto
任何“下載到S3”都隱含地意味着“下載然后上傳到S3” - 無論是手動上傳還是像boto這樣的腳本或庫。
如果使用腳本或庫(boto),它會將映像下載到連接到其運行的系統的文件系統 - 本地工作站或服務器 - 然后使用AWS密鑰和庫將其上載到S3。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.