【问题标题】:Why MulterS3 defines .excel .docs as application/zip files what can I do with it?为什么 MulterS3 将 .excel .docs 定义为应用程序/zip 文件我可以用它做什么?
【发布时间】:2022-12-22 18:30:28
【问题描述】:

在这段代码中,我输出了 mime 文件类型。加载时.docs要么.excel我得到申请结果/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));
        }
    ]
)

结果

application/zip

【问题讨论】:

  • 我刚刚发现了同样的问题。您找到解决方案了吗? @MiyRon
  • 再会!是的,我回答了我自己的问题希望它能帮助你!

标签: node.js linux express multer-s3


【解决方案1】:

只需添加文件.原始名称

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));
        }
    ]
)

【讨论】:

    猜你喜欢
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-21
    • 1970-01-01
    • 2022-11-30
    • 2018-01-07
    相关资源
    最近更新 更多