Hugo Da Roit
Hugo Da Roit

Reputation: 437

Piping a multipart file upload to a S3 bucket

I would like to pipe a file upload that I receive from a multipart request to a S3 bucket using express and aws-sdk.

I use the upload function, it can use a readable stream for the Body parameter.

await s3Client
  .upload({
    Bucket: 'some_bucket',
    Key: `records/recordXYZ`,
    Body: req,
    ContentType: 'audio/x-wav,
  })
  .promise();

req is from express. The request is correctly parsed, the issue is that in the created file in S3 I retrieve some fields from the multipart request that I don't want into. The file is unreadable.

What is inside the file in S3 :

--JP2kMlzhqj2uAUdy4al132WFLRexf1
Content-Disposition: form-data; name="aFile"; filename="test.wav"
Content-Type: audio/wav
Content-Transfer-Encoding: binary

RIFF|  WAVEfmt ...

Want I need is only :

RIFF|  WAVEfmt ...

Upvotes: 1

Views: 1371

Answers (1)

Hugo Da Roit
Hugo Da Roit

Reputation: 437

Got it working with multer-s3 : https://github.com/badunk/multer-s3

Upvotes: 1

Related Questions