显示来自 Gridfs 的图像

Display images from Gridfs

我对节点完全陌生,想知道如何下载带有网格的图像。请帮我。 我使用 mongoose 和 node 来存储图像,侧前端 nodeJs。我想在 nodejs 中使用网格下载图像。

db.open(function (){
    gfs.exist({ _id: id }, function(err, found) {
       gfs.createReadStream({ _id: id }).pipe(res);
    });
});

如有任何帮助,我们将不胜感激。

根据您的问题,gridfs 是您可以使用的最佳选择。

 if (fileExists(image_name) == false) { //it check that file exist or not   
            var file = fs.createWriteStream(image_name);
            http.get(url, function (response) {
                response.pipe(file);
            })
        }
        else {
            console.log('already exist.');
        }

我正在我的代码中使用它,希望它对你有用。