Search code examples
node.jslinuxexpressmulter-s3

Why MulterS3 defines .excel .docs as application/zip files what can I do with it?


In this block of code, I output the mime file type. When loading .docs or .excel I get the result of application/zip

const upload = multer({
    limits: {
        fieldSize: 10000000 //10MB
    },
    storage: multerS3({
        s3: s3Client,
        bucket: 'bucket',
        acl: 'public-read',
        contentType: multerS3.AUTO_CONTENT_TYPE,
        key: function (req, file, cb) {
            cb(null, 'attachments/' + uuidv4())
        },
    })
})

export const post = compose(
    [
        isAuth,
        upload.array('files[]', 10),
        async (req, res) => {
            req.files.forEach(file => {
                console.log(file.contentType)
            });
            return res.json(req.files.map(i => i.location));
        }
    ]
)

RESULT

application/zip

Solution

  • Just add file.originalname

    const upload = multer({
        limits: {
            fieldSize: 10000000 //10MB
        },
        storage: multerS3({
            s3: s3Client,
            bucket: 'bucket',
            acl: 'public-read',
            contentType: multerS3.AUTO_CONTENT_TYPE,
            key: function (req, file, cb) {
                cb(null, 'attachments/' + uuidv4() + file.originalname)
            },
        })
    })
    
    export const post = compose(
        [
            isAuth,
            upload.array('files[]', 10),
            async (req, res) => {
                return res.json(req.files.map(i => i.location));
            }
        ]
    )