Serverless File Uploader with AWS HTTP Gateway and S3 - Step by Step Tutorial
ฝัง
- เผยแพร่เมื่อ 4 ม.ค. 2022
- Lambda Code:
------------------------
import json
import base64
import boto3
client=boto3.client('s3')
def lambda_handler(event, context):
TODO implement
print(event)
ms=base64.b64decode(event['body'])
response = client.put_object(
Body=ms,
Bucket='demouploadfromapilambda',
Key='test1.PNG',
)
print(response)
return {
'statusCode': 200,
'body': json.dumps('Image uploaded successfully')
}
Check this playlist for more AWS Projects in Big Data domain:
• Demystifying Data Engi... - วิทยาศาสตร์และเทคโนโลยี
Thanks bro, for making it easy!
Any time!
simply fabulous
Thank you so much for your kind words Mohammed Abu! Happy Learning
Thanks bro, you r best amk
You are welcome buddy 😊 Happy Learning ✌🏻
Hi Dear, Here Image file name is hard coded. how we can make it dynamic as I don't see any key holding filename. Thanks
You can read image file name
Or you many people prefer random image name from uuid or nanoid
Hi. I was able to successfully upload to S3 but when I download the PNG it is not opening saying as unsupported format
are you uploading jpg file and saving as .png or something ? I mean have you given proper format ?
@@KnowledgeAmplifier1 yeah I'm uploading .png and saving the key in same .png only but not sure why it is not opening
@@KnowledgeAmplifier1 hey sorry I made some mistake in code. Now I have resolved that.. thanks bro
@@manojt7012 super , Glad to know it's resolved ! Happy Learning :-)
@@manojt7012 hey, I have same problem. so, can you explain me what you did?
I'm uploading .jpg file and .png file successfully but when i download from s3 bucket it's not accessible.