Node Express将图像文件发送为API响应

我谷歌search,但无法find答案,但它必须是一个共同的问题。 这与节点请求(读取图像stream – pipe道回到响应)相同的问题,这是没有答案。

如何将图像文件作为Express .send()响应发送? 我需要将RESTful url映射到图像 – 但是如何将正确的头文件发送给二进制文件? 例如,

<img src='/report/378334e22/e33423222' /> 

电话…

 app.get('/report/:chart_id/:user_id', function (req, res) { //authenticate user_id, get chart_id obfuscated url //send image binary with correct headers }); 

Express中有一个API。

res.sendFile

 app.get('/report/:chart_id/:user_id', function (req, res) { // res.sendFile(filepath); }); 

http://expressjs.com/en/api.html#res.sendFile