Following situation: A user sends an image to facebook messenger and facebook provides an url that looks like this
I am storing this url in a variable called url. Now I would like to upload that image to my 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)
However, like this Python throws me an error no such file or directory with regard to the url. What's the way to go?
As suggested by @jordanm downloading the file to the django project static folder, uploading it from there to S3 and then deleting the file then from static worked.