Express.js / generated image

I am using an expression, and I would like to serve the generated image. The html source is something like <img src="/generated/image"> and setting the route, so when GET to /generated/image is called, PNG is created (and placed, for example, in a shared directory, but I think this is not strictly necessary). Now I would like to send this image to the user. Should I use res.send() for this purpose? How can I get data to the user?

+6
source share
1 answer

Depending on the library that you use to create the image, you should be able to res.end(image, 'binary'); Remember to include the correct Content-Type header.

If you do not want to generate a file every time you can write the file to disk, store it in the key / value repository, relational database, etc ... and check / maintain it if it has already been created before go through the creation procedures.

+9
source

Source: https://habr.com/ru/post/905972/


All Articles