以下情况:用户向facebook messenger发送图像,facebook提供了一个类似于此的网址
我将此url存储在名为url的变量中。现在我想将该图像上传到我的AWS S3:
import boto
import os
AWS_ACCESS_KEY_ID = ‘somekey’
AWS_SECRET_ACCESS_KEY = 'somesecret'
END_POINT = 'us-east-1'
S3_HOST = 's3.us-east-1.amazonaws.com'
BUCKET_NAME = 'somestorage'
def upload_s3(url):
fname = url
uploaded_fname = 'somename'
s3 = boto.s3.connect_to_region(END_POINT,
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
host=S3_HOST)
bucket = s3.get_bucket(BUCKET_NAME)
k = Key(bucket)
k.key = uploaded_fname
k.set_contents_from_filename(fname)
但是,像这样的Python会抛出一个错误,没有关于url的文件或目录。怎么走?
答案 0 :(得分:0)
正如@jordanm建议将文件下载到django项目静态文件夹,将其从那里上传到S3,然后从静态工作中删除文件。