anacronw/multer-s3

MS Office (.xlsx, .docx) being assigned application/zip ContentType when using AUTO_CONTENT_TYPE

Opened this issue · 2 comments

const multerStorage = multerS3({ s3: s3, acl: 'public-read', contentType: multerS3.AUTO_CONTENT_TYPE, contentDisposition: 'attachment', bucket: process.env.S3_BUCKET, });

This works for all files except for MS Office, .docx, .xlsx, .pptx .... I see that you are using file-type to detect and set the proper ContentType. Is this a known issue?

It seems like we just need to update the version of file-type in order to fix this...

I know that they have made a few breaking changes lately, and we are on a very old version. If anyone could find out which version we can upgrade to without breaking anything for users of this library, we could release that as 3.1.0.

Long term we could upgrade to the latest version in 4.0.0.

Hello folks, I'm saying Hi from Brazil.

I used to have the same problem by here. And... I have a solution that don't need to update anything!

So, I added a property called contentDisposition to the MulterS3 construtor in my code. Like this:

module.exports = {
  configuration: multer({
    storage: multerS3({
      [...]
      contentDisposition: 'attachment', // I'm not sure if this affects this problem, but seems right to be here for me
      [...]
    }),
  })
}

Futhermore, to every S3 signing operation, it will be necessary to add this param:
ResponseContentDisposition: `attachment; filename="${key}"`, where key can be the name of the file

Ps.: I almost forgot to say that this blog made me realize what was forgetting to parametrize. The best thing is that I didn't need to change the encode of any files on my file server, they were all perfect.