[英]res.send(imgPath) does not send image when content-type is set to image
響應不發送S3圖像,而是獲取本地路由路徑:
route.get('/file');
res.setHeader('content-type', result.file_type);
res.send(imgPath);
我得到路由路徑(“文件”)作為響應,並帶有黑屏。 我想要的是獲得圖像
而不是發送文件路徑作為響應,請以二進制格式傳遞圖像數據。 請使用以下代碼:
app.get('/file', function (req, res) {
var img = fs.readFileSync('./logo.png');
res.writeHead(200, { 'Content-Type': 'image/gif' });
res.end(img, 'binary');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.