S
S
superivankorolev2017-02-03 12:44:53
Node.js
superivankorolev, 2017-02-03 12:44:53

How to send an image to the frontend in React, which is placed in the new Buffer object?

In express it was done like this:

res
      .set('Content-Type', 'image/jpeg')
      .send(imageBuffer);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Gushchin, 2017-02-03
@iNikNik

If you want to insert an image directly into the html - https://www.npmjs.com/package/datauri#from-a-buffer :

const datauri = new Datauri()
datauri.format('.png', imageBuffer)
console.log(datauri.content) //=> "data:image/png;base64,eGtjZA=="

Well, in other cases: insert the url of your image into img.src and send it by express.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question