diff --git a/AWS_FileUpload_To_S3_Bucket_With_API_Gateway_And_Lambda/010.png b/AWS_FileUpload_To_S3_Bucket_With_API_Gateway_And_Lambda/010.png new file mode 100644 index 0000000..e7e0260 Binary files /dev/null and b/AWS_FileUpload_To_S3_Bucket_With_API_Gateway_And_Lambda/010.png differ diff --git a/AWS_FileUpload_To_S3_Bucket_With_API_Gateway_And_Lambda/InvokeAPIToUploadFile.py b/AWS_FileUpload_To_S3_Bucket_With_API_Gateway_And_Lambda/InvokeAPIToUploadFile.py new file mode 100644 index 0000000..90d6f21 --- /dev/null +++ b/AWS_FileUpload_To_S3_Bucket_With_API_Gateway_And_Lambda/InvokeAPIToUploadFile.py @@ -0,0 +1,23 @@ +import requests +import io +from PIL import Image +import os + +url = "" + + +#image = Image.open(os.getcwd()+"/webcaptures/Y5DOKA9GXL.png") +image = Image.open("./webcaptures/010.png") +stream = io.BytesIO() +image.save(stream,format="PNG") +image_binary = stream.getvalue() + +APIGatewayKey = "" +headers = { + 'Content-Type': 'application/png', + 'x-api-key': APIGatewayKey +} + +response = requests.request("POST", url, headers=headers, data=image_binary) + +print(response.text) diff --git a/AWS_FileUpload_To_S3_Bucket_With_API_Gateway_And_Lambda/Lambda.py b/AWS_FileUpload_To_S3_Bucket_With_API_Gateway_And_Lambda/Lambda.py new file mode 100644 index 0000000..a80edcd --- /dev/null +++ b/AWS_FileUpload_To_S3_Bucket_With_API_Gateway_And_Lambda/Lambda.py @@ -0,0 +1,28 @@ +import json +import base64 +import boto3 +import string +import random + + + +def lambda_handler(event, context): + s3 = boto3.client("s3") + + get_file_content = event["body-json"] + + decode_content = base64.b64decode(get_file_content) + + pic_filename = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10)) + + s3_upload = s3.put_object(Bucket="",Key=pic_filename+".png",Body=decode_content) + + # TODO implement + + return { + + 'statusCode': 200, + + 'body': json.dumps('The Object is Uploaded successfully!') + + } \ No newline at end of file