1

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
MiyRon
  • 406
  • 7
  • 15

1 Answers1

0

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));
        }
    ]
)
MiyRon
  • 406
  • 7
  • 15