【问题标题】:MEAN stack display image stored using muller使用 muller 存储的 MEAN 堆栈显示图像
【发布时间】:2021-04-27 13:11:15
【问题描述】:

我正在为我的 Web 应用程序使用 MEAN 堆栈。我成功地能够在节点服务器上存储多个图像文件,并将其路径与其他信息一起保存在 MongoDB 中。当我发出获取数据的请求时。如何将图像文件数组和其他信息发送回客户端?

数据库中存储的是什么

[
  {
    "paintingFileLocations": [
      {
        "fieldname": "artFileLocations",
        "originalname": "logo1.png",
        "encoding": "7bit",
        "mimetype": "image/png",
        "destination": "artImages/paintings",
        "filename": "painting&1619496101680&logo1.png",
        "path": "artImages/paintings/painting&1619496101680&logo1.png",
        "size": 95523
      },
      {
        "fieldname": "artFileLocations",
        "originalname": "logo2.png",
        "encoding": "7bit",
        "mimetype": "image/png",
        "destination": "artImages/paintings",
        "filename": "painting&1619496101684&logo2.png",
        "path": "artImages/paintings/painting&1619496101684&logo2.png",
        "size": 94132
      }
    ],
    "paintingName": "Painting 1",
  }
]

这是我的获取请求

router.get('/', function(req, res) {
    Paintings.find({})
        .then(paintings => { res.send(paintings) })
        .catch(error => console.log(error))
});

【问题讨论】:

    标签: node.js mean-stack


    【解决方案1】:

    所以你正在为此使用 NodeJS... 你将拥有的东西是

    app.post('/route', (req, res, next) => {
      ...
      //code to upload the image
      ...
    
      // fetch this object from MongoDB
      const object = Model.find('---');
    
      // here return the object in the response
      res.status(200).send(object)
    })
    

    【讨论】:

    • 我不明白这里发生了什么。我正在尝试执行获取请求,然后想将图像文件和附加数据(paintingName)都发送给客户端。在问题中添加了更多信息
    猜你喜欢
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 2016-01-23
    • 2016-03-26
    • 1970-01-01
    • 2015-02-06
    • 1970-01-01
    • 2017-11-22
    相关资源
    最近更新 更多