How to upload attachment in AWS S3 Bucket from link in Python
I have worked in a Chatbot product Lily Health that helps women through facebook chatting. I need to implement a new feature that can
receive attachment from facebook and display it. When a facebook user sends any kinds of attachment, facebook first uploads the attachement in their
fbcdn then returns the attachment url link in webhooks. Facebook provides the attachment in webhook post data as json format is given below:
Facebook Messenger Platform
supports the following four attachment types, specified in the attachment.type property of the message:
I have planned to store the attachment in AWS S3 Bucket from the facebook attachments payload url and upload the attachment S3 bucket url in my database so that I can display it later.
Here I have uploaded the attachment folder wise consider the attachment type.
So First I have to create a S3 bucket and you can follow this tutorial
Create an Amazon S3 Bucket.
After creating the bucket I need to public the bucket and you can follow my tutorial to make
S3 Bucket Public.
From S3 bucket we need the following attributes
AWS_ACCESS_KEY_ID
AWS_SECRET_KEY
AWS_REGION
AWS_BUCKET_NAME
AWS_S3_ENDPOINT
I have written a python function upload_file_to_aws_s3 that takes two parameter one is url and another is file type and this function return upload attachment
S3 Bucket url.
If your AWS_BUCKET_NAME is mrk-lily-bucket,
AWS_S3_ENDPOINT is s3-ap-southeast-1.amazonaws.com and
key is image/71384073_2440261556255816_5718908083162316800_n.png then
return url will be: