Skip to content

Commit

Permalink
qr download api success
Browse files Browse the repository at this point in the history
  • Loading branch information
lahirumenik committed Jan 27, 2024
1 parent 22ae030 commit 67b0070
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions backend/serverless/Lambda/qrdownload.py
Original file line number Diff line number Diff line change
@@ -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}),
}

0 comments on commit 67b0070

Please sign in to comment.