使用 nodejs 显示来自 gridfs 的图像
Display images from gridfs with nodejs
我使用 api sails 和 mongo 来存储图像,侧前 nodeJs
我要下载 X 张图片,只有一张图片,代码在功能上是:
db.open(function (){
gfs.exist({ _id: id }, function(err, found) {
if (err) {
return err.negotiate(err);
}
if (!found) {
return res.negotiate('No file found');
}
gfs.createReadStream({ _id: id }).pipe(res);
});
});
要下载x张图片......没有想法....
感谢您的帮助
i am doing it by using this
if (fileExists(image_name) == false) { //check the file exist or not
var file = fs.createWriteStream( image_name);
http.get(url, function (response) {
response.pipe(file);
})else{
console.log('already exist.');
}
});
希望对您有所帮助。
我使用 api sails 和 mongo 来存储图像,侧前 nodeJs 我要下载 X 张图片,只有一张图片,代码在功能上是:
db.open(function (){
gfs.exist({ _id: id }, function(err, found) {
if (err) {
return err.negotiate(err);
}
if (!found) {
return res.negotiate('No file found');
}
gfs.createReadStream({ _id: id }).pipe(res);
});
});
要下载x张图片......没有想法....
感谢您的帮助
i am doing it by using this
if (fileExists(image_name) == false) { //check the file exist or not
var file = fs.createWriteStream( image_name);
http.get(url, function (response) {
response.pipe(file);
})else{
console.log('already exist.');
}
});
希望对您有所帮助。