Angularjs 如何将缓冲区作为图像发送?
我将图像存储在GridFS中,我编写了代码将图像取出并将其转换为缓冲区,但我似乎找不到足够的文档来告诉我如何使用缓冲区来渲染图像。我使用的是平均堆栈 这是我的代码:Angularjs 如何将缓冲区作为图像发送?,angularjs,node.js,mongodb,express,buffer,Angularjs,Node.js,Mongodb,Express,Buffer,我将图像存储在GridFS中,我编写了代码将图像取出并将其转换为缓冲区,但我似乎找不到足够的文档来告诉我如何使用缓冲区来渲染图像。我使用的是平均堆栈 这是我的代码: exports.getFax = function (req, res) { var MongoClient = require('mongodb').MongoClient; Grid = require('mongodb').Grid; MongoClient.connect("mongodb://loc
exports.getFax = function (req, res) {
var MongoClient = require('mongodb').MongoClient;
Grid = require('mongodb').Grid;
MongoClient.connect("mongodb://localhost:27017/test", function (err, db) {
var gs = require('mongodb').GridStore(db, '544f9c11759c7418566019b3,', "w");
gs.open(function (err, data) {
console.log(data);
console.log(data.length);
gs.read([data.length], function (err, data) {
console.log(data);
console.log(err);
if (!err)
res.send(data);
})
});
});
};
log(数据)读取
我不太确定如何继续,因为我对GridFS还是比较陌生,在文件系统中使用缓冲区而不是图像。非常感谢您提供的任何帮助。请勿使用阅读。改用流
:
我不知道这个代码是否有效。。。只需查看文档,但请尝试以下操作:
gs.stream(true).pipe(res);