【问题标题】:Transform images into thumbnails before uploading to S3 in nodejs在 nodejs 中上传到 S3 之前将图像转换为缩略图
【发布时间】:2017-12-12 22:37:18
【问题描述】:

我已经尝试 multer-s3 好几个小时了,但我无法创建缩略图。谁能告诉我如何运行它?

以下是我的代码:

var upload = multer({
    storage: multerS3({
        s3: s3,
        bucket: 'test',
        // shouldTransform: function (req, file, cb) {
        //     cb(null, /^image/i.test(file.mimetype))
        // },
        acl: 'public-read',
        contentType: multerS3.AUTO_CONTENT_TYPE,
        shouldTransform : function (req, file, cb) {
            console.log('in should transform ', file)
            cb(null, /^image/i.test(file.mimetype))
        },
        transforms: [{
            id: 'original',
            key: function (req, file, cb) {
                console.log('original')
                cb(null, "original")
            },
            transform: function (req, file, cb) {
                console.log('original1')

                cb(null, sharp().jpg())
            }
        }, {
            id: 'thumbnail',
            key: function (req, file, cb) {
                console.log('thumbnail')

                cb(null, "thumbnail")
            },
            transform: function (req, file, cb) {
                console.log('thumbnail1')

                cb(null, file.resize(100, 100).jpg())
            }
        }]
    })
})


 app.post('/upload', upload.single('image'), extendTimeout, function(req, res, next) {
        console.log('filessss ', req.file )
        res.send('Successfully uploaded ' + req.file + ' files!')
    })

原图上传成功,但调整后的图片没有。谁能指导一下?

谢谢

【问题讨论】:

  • 你好,我也在做同样的事情。但我得到这个 sharp(...).jpg 不是一个函数。我已经安装了一个尖锐的下午。你能帮帮我吗?

标签: node.js amazon-s3 multer multer-s3


【解决方案1】:

缩略图的变换方法有错别字。 而不是

cb(null, file.resize(100, 100).jpg())

应该是

cb(null, sharp().resize(100, 100).jpg())

【讨论】:

    猜你喜欢
    • 2015-12-18
    • 2019-04-24
    • 2019-02-10
    • 2017-01-27
    • 2020-10-11
    • 2018-09-14
    • 2015-01-05
    • 2016-07-02
    • 2021-09-21
    相关资源
    最近更新 更多