Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File/Buffer Size different in memory/file unreadable #750

Closed
adamwilbert opened this issue Jul 1, 2019 · 4 comments
Closed

File/Buffer Size different in memory/file unreadable #750

adamwilbert opened this issue Jul 1, 2019 · 4 comments

Comments

@adamwilbert
Copy link

adamwilbert commented Jul 1, 2019

I am using multer in memory on a lambda (failing on both the lambda and locally currently) and uploading an image to s3.

Once I get the buffer from req.file.buffer I send that to s3 (the aws sdk takes in a buffer as one of its payload options) but the file cannot be opened and the file size is quite different than that of the image in the file attached to the request.

Am I missing something?

Is there anything added to the buffer when multer reads the file from the request?

The buffer opening the file locally and the buffer from multer are completely different.

@adamwilbert adamwilbert changed the title File Size different on upload File Size different on upload/file unreadable Jul 1, 2019
@adamwilbert adamwilbert changed the title File Size different on upload/file unreadable File/Buffer Size different in memory/file unreadable Jul 1, 2019
@BryanJAraujo
Copy link

How did you resolve this?

@Doc999tor
Copy link

Can be related to #1242?

@BryanJAraujo
Copy link

Can be related to #1242?

The problem I'm having is that when trying to upload, the file that sends is different from the original. Not necessarily the file size

@BryanJAraujo
Copy link

BryanJAraujo commented Mar 7, 2024

I solved the problem. My application is running with aws lambda and API Gateway, I was researching and discovered that API Gateway has a configuration called Binary Support, so I left it as */*, redeployed the lambda application and the file was sent correctly by multipart/form-data

template.yaml:

FunctionName:
    Type: AWS::Serverless::Api
    Properties:
      BinaryMediaTypes:
        - '*/*'
      ...

Edit: It is not recommended to use */*, but rather the types of files that will be passed by the request
Suggested reading: Working with binary media types for REST APIs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants