I am trying to build an API with API gateway to accept a file upload. I am going through lambda
so that I can manipulate the file name before passing it on to S3 bucket
In the event body i can see the file contents but can't seem to access the file name.
Right now Im not implementing anything to move file to S3 because I haven't been able to access the file name.
the code is as follows
import sys
import os
import boto3
import json
def lambda_handler(event,context):
eventBody = json.dumps(event['body'])
return {
'statusCode': 200,
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
'body': eventBody,
'isBase64Encoded': False
}
the event body looks as follows
"----------------------------210938299122441198584130\r\nContent-Disposition: form-data; name=\"file\"; filename=\"test.txt\"\r\nContent-Type: text/plain\r\n\r\nthis is a test file\r\n----------------------------210938299122441198584130--\r\n"
I can see that the filename is there but I cant seem to access it.
i had been trying
filename = json.loads(eventBody)['filename']
but this does not work. is there a way to access the filename from the post request in lambda?
source https://stackoverflow.com/questions/76376126/aws-api-gateway-to-pass-file-through-lambda-to-s3-bucket
Comments
Post a Comment