I have an image file stored on s3 which i need to download on lambda and then post to a third party api for processing. I'm using axios to post the multipart form data to this api: https://developer.cynopsis.co/#/OCR/post_service_v2_ocr_
This is sounds like a straight forward task but i'm obviously missing something.
My Code:
Set the s3 params:
const params: S3.Types.GetObjectRequest = {
'Bucket': bucket,
'Key': keyName,
'ResponseContentType': 'image/jpg'
};
Download the object:
const data = await this.s3Client.getObject(params).promise();
Create a new instance of Form Data with the downloaded data:
const formData = new FormData();
formData.append("file0", data.Body, { filename: 'file.jpg', contentType: "image/jpg" });
formData.append("isAsync", 'false');
Pass to the third party api:
const axiosRequestHeaders: AxiosRequestConfig = {
headers: {
Authorization: `Bearer ${this.aresAccessToken.accessToken}`,
...formData.getHeaders()
}
}
const response = await axios.post(axiosRequestUrl, formData, axiosRequestHeaders)
If i try a very small file, 20Kb or less then this works fine. However, any larger and the third party api returns a 400 Bad Input Parameter.
If i post the large file directly from my laptop to the third party api using Postman its fine.
The documentation on the api linked above says that the error relates to "Bad Request due to unsupported file type or missing required data". I'm therefore thinking that somehow the request body of the image is truncated in someway before it is sent, but i can't figure out what exactly i'm doing wrong.
I've also tried writing the file to /tmp folder in lambda and then using fs.createReadStream() to pass the data but i get the same issue.
Thanks a million in advance