I am trying to do this:
- Frontend: set up file to upload using <input type="file">and<input type="button" onClick="...">
- The File Object is retrieved using file[0]from the<input type="file">'s value.
- Use Javascript Fetchapi to call on my AWS API-GatewayPostAPI.
I have tried both multipart/form-data and application/json in the request.
- On the AWS Lambda, I have used Buffer Object to consume the body.
I have tried using Buffer(body, "utf8"), Buffer(body, "base64"), Buffer(body, "binary").
- This is, in turn, pushed up to S3for storage usingputObject.
Problem:
- The file object that was set up in - S3has either filesize 0 or some random value that's not matching the original filesize.
- The file downloaded from - S3cannot be opened.
Failed Approaches
I have considered multer and multiparty. These seem to be ExpressJS middleware and expects a HttpRequest object as input (this wasn't mentioned explicitly. It seems like I am ignorant enough not to assume that these can only work with HttpRequest object and it took me a while to find out). I am also ignorant enough not to know how to transform an AWS event object into a HttpRequest object. But that said, it seems excessive to use Express engine just for the sake of managing file upload.
Exposing my S3 bucket as public-read-write seems to be rather insecure. So I am not considering the frontend directly moving stuff in/out of my S3 bucket. 
My Request
Can anyone tell me how to get this to work? And/or an alternative to this approach?
 
    