1

Hi I'm trying to send an image buffer through http between servers, from server A to server B.

My Server B snippet goes like this:

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

My server A snippet goes like this:

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')
    }
}

In other words, server A sends image to server B and it append some text to the image, then it send the image back to server A, and there is where the problem gets prompted:

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

Image is correctly send to server B, because I was able to save it locally. But as soon as I tried to send it back to srver A, I got stucked.

What do you think is happening here and how would I fix it? Thanks a lot

Clown
  • 183
  • 1
  • 10

0 Answers0