myshenin / aws-lambda-multipart-parser

Parser of multipart/form-data requests for AWS Lambda
MIT License
74 stars 38 forks source link

Getting a malformed buffer #12

Closed davidgatti closed 5 years ago

davidgatti commented 6 years ago

I'm running in this situation where the buffer that I get back from this module, is not correct. For example images won't be displayed because of this. It seams to me that your code is parsing the binary data from the request incorrectly.

myshenin commented 6 years ago

@davidgatti show an example

Tutch commented 6 years ago

I'd also like to know about this. I'm trying to save an .webm file and while the resulting file size is correct, the video does not open. Maybe it's the file writing in itself that's not right? Here's my code:

module.exports.handler = (event, context, callback) => {
    let data = multipart.parse(event, true);

    fs.writeFile('test.webm', data.file.content, 'binary', function(err) {
        if(err) { 
          console.log(err);
        } else {  
          console.log('saved');
        }
      }); 
};
sparent commented 6 years ago

+1 running into the same issue, incorrect buffer causing corrupted file

Tutch commented 6 years ago

Seems to be a problem on serverless offline's end. Refer to this issue.

sparent commented 6 years ago

@Tutch I applied the changes referenced in that issue and got it working :thumbsup:

myshenin commented 6 years ago

@Tutch @sparent what are changes helped you?

Tutch commented 6 years ago

@myshenin the solution in this issue right here solved the problem. But there's no need to worry anymore, because serverless-offline accepted the solution on this merge request here. The current version of serverless-offline works as expected with this multiparser.

myshenin commented 6 years ago

@Tutch as I understood the issue is in encoding? I tried to fix it with toString('binary') but it didn't work

myshenin commented 6 years ago

Unfortunately, there is an issue with malformed media files uploaded to S3. Let me explain on example, I send an image, which is 50Kb. I get a buffer, which is 50Kb. That fact indicates buffer is formed well, but some encoding issue happens with s3.upload and s3.putObject functions. If you have a solution or a hint, contact me myshenin.contact@gmail.com. @Tutch @sparent @davidgatti

djgovani commented 5 years ago

@myshenin You can refer my repo . Hope it'll help you

AgentGoldPaw commented 5 years ago

@djgovani I tried your implementation for pdf files and it didn't help. Does anyone have another idea?