如何使用vue-image-compressor发送图像并返回节点?

时间:2018-10-26 09:40:50

标签: node.js vue.js multer cloudinary

我在节点上有一个api,它使用multer将我的图像托管在cloudinary上。但是,我必须先压缩发送的文件,然后再上传。我按照vue-compressor githubs页面上的教程进行操作,但是现在,我需要怎么做才能将blob图像或其任何内容转换为节点api中的文件?

这是我的后退代码:

let storage = cloudinaryStorage({
    cloudinary: cloudinary,
    folder: '/my-folder',
    allowedFormats: ['jpg', 'jpeg', 'png'],
    width: 250,
    height: 250,
    quality: 10,
    crop: "limit",
    filename: function (req, file, cb) {
        cb(undefined, md5(new Date().getTime() + new Date()));
    }
});

let parser = multer({ storage: storage });
router.post('/photo', auth.authorize, parser.single('foto'), function (req, res) {

    let retorno = new Promise((resolve, reject) => {
        resolve(controller.alteraFoto(req.file.secure_url, req.body.aluno))})

    retorno.then((response) => {
        if (response.encontrada) {
           res.status(201).send({ 'message': response.message, 'foto': response.foto });
        })
    }
});

0 个答案:

没有答案