I am trying to upload image to my s3 bucket , below is the lambda function:
import json
import base64
import boto3
client = boto3.client('s3')
def lambda_handler(event, context):
# TODO implement
print('Started')
imageDecoded = base64.b64decode(event['body'])
response = client.put_object(
Body = imageDecoded,
Bucket = 'sulabhtest',
key = "thisKey.jpg",
)
return {
'statusCode' : 200,
'body' : json.dumps('Image Uploaded')
}
and in cloud watch i am seeing error at line : imageDecoded = base64.b64decode(event['body'])
that image contains ASCII character. how to resolve this error? i am uploading png/jpg image from postman
[ERROR] ValueError: string argument should contain only ASCII characters
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 10, in lambda_handler
imageDecoded = base64.b64decode(event['body'])
File "/var/lang/lib/python3.9/base64.py", line 80, in b64decode
s = _bytes_from_decode_data(s)
File "/var/lang/lib/python3.9/base64.py", line 39, in _bytes_from_decode_data
raise ValueError('string argument should contain only ASCII characters')