Skip to content

Commit

Permalink
File Upload
Browse files Browse the repository at this point in the history
  • Loading branch information
naeemaa00 committed Sep 1, 2023
1 parent d38fb49 commit 78b55be
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import requests
import io
from PIL import Image
import os

url = "<Your API Gateway URL with Resource value>"


#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 = "<Your API Gateway Key>"
headers = {
'Content-Type': 'application/png',
'x-api-key': APIGatewayKey
}

response = requests.request("POST", url, headers=headers, data=image_binary)

print(response.text)
28 changes: 28 additions & 0 deletions AWS_FileUpload_To_S3_Bucket_With_API_Gateway_And_Lambda/Lambda.py
Original file line number Diff line number Diff line change
@@ -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="<Your Bucket Name>",Key=pic_filename+".png",Body=decode_content)

# TODO implement

return {

'statusCode': 200,

'body': json.dumps('The Object is Uploaded successfully!')

}

0 comments on commit 78b55be

Please sign in to comment.