A REST API endpoint for receiving an image and uploading it to S3

Hello all!

It seems like this is a common occurrence when it comes to the Serverless Framework. That image & file uploading is broken through the framework. I have created an express application.

I have an endpoint which is handled by a middleware and finally a function.

The middleware is a simple config of the library “multer”:

However, when Multer stores the image in the local storage it turns out the image is broken.
(“An error occured while loading the image”)

The same exact code works in a Serverless-free Express.js application. I am utterly confused. Does anyone have any idea what is up?

The upload of files via API Gateway and Lambda is not the recommended practice. Its just not made to handle that use case elegantly and even if you got past your current issues you would come across others related to file size limits and more. The recommended best practice when it comes to doing file uploads using Serverless is to use a Lambda to generate a one time URL to upload into S3.