簡體   English   中英

當content-type設置為image時,res.send(imgPath)不發送圖像

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM