0
Gridfs가있는 MongoDB에 여러 이미지가 업로드되었습니다. 내가 looped하고 base64 형식으로 이러한 이미지를 배열로 전달하고 nodejs 통해 표시하려고합니다.동일한 이미지가 배열에 저장 됨 - nodejs
나는 내가이 코드를 실행하면 동일한 이미지가 반복되는이
var promise = new Promise((resolve, reject) => {
console.log('open');
var gfs = Grid(conn.db);
gfs.files.find({}).toArray(function(err, files) {
if (err) {
throw (err);
}
for (var i = 0; i < files.length; i++) {
readstream[i] = gfs.createReadStream({
_id: files[i]._id
});
console.log(files[i]._id);
readstream[i].on('data', function(chunk) {
bufs.push(chunk);
console.log("readstream on data");
});
readstream[i].on('end', function() {
fbuf = Buffer.concat(bufs);
base64 = Buffer(fbuf).toString('base64');
console.log("readstream on end");
result.push(base64);
fbuf = null;
base64 = null;
});
}
});
if (result != undefined) {
console.log("resolve promise if");
resolve(result);
}
else {
console.log("reject promise if");
resolve(result);
}
});
promise.then(function(result) {
console.log("resolve promise.then");
res.render("report_missing.ejs", { result2: result });
},
function(result) {
console.log("reject promise then ");
});
을 달성하기 followiing 코드가 있습니다. 내가 새로 고침 할 때 표시되는 이미지도 변경됩니다.
내가 모듈을 발견 잘못
감사 Gaurav