I an API endpoint that accepts files as input. And I would like to use S3 files to be processed in that API endpoint.
Now doing it in my local file is pretty simple.
response = requests.post(url_endpoint, files={'files': open('myFile.pdf', 'rb')})
But when I do it in AWS Lambda using the S3 file, I can't seem to get it to work.
s3 = boto3.client('s3')
myFile = s3.get_object(Bucket=bucketName, Key=fileKeyName)['Body'].read()
response = requests.post(url_endpoint, files={'files': myFile})
Boto3 get_object seems to be in a different format than open('myFile.pdf', 'rb')
.
How do I get this to work?
CodePudding user response:
Found the answer here. How to post a multipart/form-data using a file from AWS S3
Not sure where the documentation is, but this is what I did.
response = requests.post(url_endpoint, files={'files': (fileKeyName, myFile, 'application/doc;charset=utf8')})