首页 > 解决方案 > 错误找不到缓冲区的 MIME吉普

问题描述

嗨,我正在尝试通过服务器之间的 http 发送图像缓冲区,从服务器 A 到服务器 B。

我的服务器 B 片段如下所示:

app.post('/image', (req, res) => {
  Jimp.read(Buffer.from(req.body.buffer.data))
    .then(image => {
      axios.get('https://geek-jokes.sameerkumar.website/api?format=json').then(function (response) {
            Jimp.loadFont(Jimp.FONT_SANS_64_WHITE).then(font => {
              const width = image.bitmap.width;
              const height = image.bitmap.height;
              image.print(font, width * 20 / 100, height * 80 / 100, response.data.joke);
              res.send(image.bitmap.data) // <<--- Sending Bitmap HERE
            });
        }).catch(function (error) {
                console.error('Error ' + error.message)
            })
    }).catch(err => {
    console.log(err)
  });
})

我的服务器一个片段是这样的:

const imgUpload = (req, res) => {
    const byteContent = req.file
    if (byteContent) {
        axios.post('http://127.0.0.1:4000/image',
            byteContent).then(function (response) {
                Jimp.read(Buffer.from(JSON.stringify(response.data)))
                    .then(image => {
                        image.write('public/uploads/aja.jpg')
                    }).catch(function (error) {
                        console.error('Error ' + error.message)
                    })
            }).catch(err => {
                console.log(err)
            });
    } else {
        res.send('Something went wrong :c')
    }
}

换句话说,服务器 A 将图像发送到服务器 B 并在图像上附加一些文本,然后将图像发送回服务器 A,并提示问题:

"Error Could not find MIME for Buffer <null>"

图像已正确发送到服务器 B,因为我能够将其保存在本地。但是,当我尝试将其发送回服务器 A 时,我就卡住了。

你认为这里发生了什么,我将如何解决它?非常感谢

标签: node.jsimagehttpbufferjimp

解决方案


推荐阅读