gpt4 book ai didi

image - Node Express 发送图像文件作为 API 响应

转载 作者:IT老高 更新时间:2023-10-28 21:54:43 24 4
gpt4 key购买 nike

我用谷歌搜索了这个,但找不到答案,但这一定是一个常见问题。这与 Node request (read image stream - pipe back to response) 的问题相同。 ,这是没有答案的。

如何将图像文件作为 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

关于image - Node Express 发送图像文件作为 API 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17515699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com