6

I am using express and I would like to serve a generated image. The html source is something like <img src="/generated/image"> and the route setup so when a GET to /generated/image is called, a PNG gets created (and put, for example, in the public directory, but I guess this is not strictly necessary). Now I'd like to send back that image to the user. Should I use res.send() for that purpose? How can I get the data to the user?

0

1 Answer 1

10

Depending on library you're using to create the image, you should be able to res.end(image, 'binary'); Make sure to include the correct Content-Type header.

If you don't want to generate the file every time you can write the file to disk, store in a key/value store, relational database, etc... and check/serve if it has already been created before going through the creation routines.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.