From 5e16e7fbb8ae57ba2a834f1a17acda90f0998b16 Mon Sep 17 00:00:00 2001 From: Mahdis Date: Mon, 15 Jul 2024 19:37:23 -0400 Subject: [PATCH] add template --- back/movie_lambda/lambda_function.py | 9 +++++---- front/frontend-request.py | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/back/movie_lambda/lambda_function.py b/back/movie_lambda/lambda_function.py index 511af68..318915b 100644 --- a/back/movie_lambda/lambda_function.py +++ b/back/movie_lambda/lambda_function.py @@ -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) diff --git a/front/frontend-request.py b/front/frontend-request.py index de0e8f8..21f04c6 100644 --- a/front/frontend-request.py +++ b/front/frontend-request.py @@ -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 = { @@ -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.')