【问题标题】:Display images from Gridfs显示来自 Gridfs 的图像
【发布时间】:2017-06-23 14:55:57
【问题描述】:

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

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

任何帮助将不胜感激。

【问题讨论】:

    标签: node.js mongodb mongoose gridfs


    【解决方案1】:

    根据您的问题,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.');
            }
    

    我在我的代码中使用了这个,希望这对你有用。

    【讨论】:

      猜你喜欢
      • 2014-04-08
      • 2016-04-27
      • 2012-05-22
      • 2018-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-21
      • 1970-01-01
      相关资源
      最近更新 更多