nodejs expressjs 將 圖片二進位制資料顯示為圖片
阿新 • • 發佈:2019-01-28
不容易啊,搞這個搞了幾天,沒有資源,還好,總是搞出來了,呵呵
宣洩下,呵呵,不多說了,直接程式碼:
exports.show = function(req, res, next){title = req.params.title; //引數
console.log(title);
var query = conn.query('select * from '+TEST_TABLE+' where title="'+title+'"',
function(err,rows,fileds){
var imgs = '';
//console.log(rows);
img = rows[0].text; //從資料庫中得到圖片二進位制資料
// console.log(img);
res.writeHead('200', {'Content-Type': 'image/jpeg'}); //寫http頭部資訊
res.end(img,'binary'); //res結束,把圖片顯示出來也可以res.write(img,'binary')
});
};