francismeynard / lambda-multipart-parser

This nodejs module will parse the multipart-form containing files and fields from the AWS lambda event object. It works very well parsing binary and text files.
MIT License
67 stars 25 forks source link

Corrupted files after being parsed #7

Open ghost opened 3 years ago

ghost commented 3 years ago

Hello,

I am having an issue where my files are being corrupted. I have checked the previous issues and made sure "Binary Media Types" are correct: image

I have also made sure Lambda proxy is setup: image

Any ideas as to what my issue is?

Davste93 commented 3 years ago

To anyone else who sees this, you probably didn't pass on the content type and accept properties inside the API gateway. The response you should be getting should be base64.

cabraljv commented 3 years ago

same problem here

courtyenn commented 2 years ago

@cabraljv I solved this by following the instructions here: https://stackoverflow.com/a/62819124/1786840

... Don't forget to hit "Deploy API".

michari commented 1 year ago

It's not working, I see no proper solution can anyone suggest how to solve it?

Still does not work.

If the file is 30Kb when I pass it to S3 and save it its only 27.8Kb

I get this when I print the file object but I use the same content for S3 body the file is corrupted.

{
    content: <Buffer fd fd fd fd 00 10 4a 46 49 46 00 01 01 00 00 48 00 48 00 00 fd fd 00 40 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 01 fd 69 00 04 00 00 00 01 00 00 ... 445388 more bytes>,
    filename: 'MyImage.jpg',
    contentType: 'image/jpeg',
    encoding: '7bit',
    fieldname: 'image'
}
Vibinreji commented 1 year ago

Hi @michari Did you resolve the issue? Now I am facing the same issue.Could you please help me if you found any solution?

Shadowstep33 commented 10 months ago

For me anyways, the issue was for sure the binary media supported in API Gateway. You can do this by hand by going to API Gateway -> {Your API} -> Settings -> Edit -> Binary Media Types Make sure to use multipart/form-data and not /multipart/form-data as the placeholder text might misleadingly suggest. You can also do this automatically via SAM in your template as shown below

sam-template.yaml

Globals:
    Api:
        BinaryMediaTypes:
            - multipart/form-data

@ghost @michari @vibinreji