I am having an error that I can’t solve when sending an image through postman to an api that I have created in AWS, I process the request in a lambda function and to read the content of the image I decode it in base64 to later save it in a bucket of s3 with the following code:
def lambda_handler(event, context):
img_data = base64.b64decode(event['body'])
# Guarda la imagen en un archivo temporal
aux_path = '/tmp/{}.jpg'.format(generate_unique_id())
with open(aux_path, 'wb') as f:
f.write(event['body'])
# Sube la imagen a S3
bucket = 'mys3'
s3_key = '{}.jpg'.format(generate_unique_id())
s3.upload_file(aux_path, bucket, s3_key)
return {
'statusCode': 200,
'body': json.dumps({'message': 'file saved successfully'}),
'headers': {'Access-Control-Allow-Origin': '*'}
}
The problem is that when decoding the image I get the following error:
raise ValueError(‘string argument should contain only ASCII characters’)
In the API configuration I have added as binary media type / so there should not be the problem.
Any suggestions ? Thank you very much
I am trying to save an image in s3 with a lambda function. I am sending the image through postaman to an api created in aws.
Tom Smiths is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.