Skip to content

Commit

Permalink
add template
Browse files Browse the repository at this point in the history
  • Loading branch information
maahdisrostampoor committed Jul 15, 2024
1 parent fed3599 commit 5e16e7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 5 additions & 4 deletions back/movie_lambda/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ def get_parameter(parameter_name):

def lambda_handler(event, context):
try:
body = json.loads(event['body'])
image_base64 = body['image_base64']
filename = body['filename']

image_base64 = event.get("image_base64")
filename = event.get("filename")
# body = json.loads(event['body'])
# image_base64 = body['image_base64']
# filename = body['filename']
# Decode the base64 image
image_data = base64.b64decode(image_base64)

Expand Down
17 changes: 15 additions & 2 deletions front/frontend-request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
url = 'https://nnjbk1ac5a.execute-api.us-east-1.amazonaws.com/Prod/'

# Path to the image file
image_file_path = '/home/maahdis/Pictures/matrix.jpeg'
image_file_path = '/home/maahdis/Pictures/godfather.jpg'

# Prepare the image file to be sent
with open(image_file_path, 'rb') as image_file:
image_base64 = base64.b64encode(image_file.read()).decode('utf-8')
print(image_base64)

# Prepare JSON payload
payload = {
Expand All @@ -22,9 +23,21 @@
'Content-Type': 'application/json'
}


# Send POST request with JSON payload
response = requests.post(url, json=payload, headers=headers)

def rlen(response):
"""
approximate request size sent to server
"""
len_of_meth = len(response.request.method)
len_of_addr = len(response.request.url)
len_of_head = len('\r\n'.join('{}{}'.format(k, v) for k, v in response.request.headers.items()))
len_of_body = len(response.request.body if response.request.body else [])

return len_of_meth + len_of_addr + len_of_head + len_of_body

print(rlen(response))
# Check if the request was successful (status code 200)
if response.status_code == 200:
print('Image uploaded successfully.')
Expand Down

0 comments on commit 5e16e7f

Please sign in to comment.