From 67b0070b6ebe6b468ae0c909901a85ce72f9f9ac Mon Sep 17 00:00:00 2001 From: lahirumenik <115687865+lahirumenik@users.noreply.github.com> Date: Sat, 27 Jan 2024 23:55:55 +0530 Subject: [PATCH] qr download api success --- backend/serverless/Lambda/qrdownload.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/backend/serverless/Lambda/qrdownload.py b/backend/serverless/Lambda/qrdownload.py index b6d6990..5509636 100644 --- a/backend/serverless/Lambda/qrdownload.py +++ b/backend/serverless/Lambda/qrdownload.py @@ -1,21 +1,27 @@ import json import boto3 import base64 +from botocore.exceptions import ClientError + client=boto3.client('s3') def lambda_handler(event, context): + print(event) bucket_name='arcombat-qr' body_dict = json.loads(event['body']) image_file_name=body_dict['email'] - - response = client.get_object( - Bucket=bucket_name, - Key=image_file_name+'.png', -) - image_file_to_be_downloaded=response['Body'].read() + + try: + response = client.generate_presigned_url('get_object', + Params={'Bucket': bucket_name, + 'Key': image_file_name+'.png'}, + ExpiresIn=18000) + except ClientError as e: + logging.error(e) + return None + return { 'statusCode': 200, - 'body':base64.b64encode(image_file_to_be_downloaded) , - 'isBase64Encoded': True + 'body': json.dumps({'presigned_url': response}), }