javascript - 尝试获取多个图像时,Angular observable 抛出错误,状态代码为 200

标签 javascript angular postgresql express

问题描述
我在从 postgreSQL 数据库获取多个图像并将其显示在我的前端时遇到问题。图像作为二进制数据存储在 postgreSQL 中。如果我运行我的快速代码,我会以 json 格式将图像数据作为缓冲区返回。
当我运行代码时,我收到一个 200 状态代码,但 observable 最终执行了 handleError 函数。
在这里你可以看到我的控制台 --> console
我的目标
我想从房子中获取多张图像以显示在我的前端模态页面上,这些图像存储在数据库中的单独表中。有了这个查询 ("select * from housee.houses_images where straatnaam = $1 AND straatnr = $2 AND postcode = $3",) 在我的 postgreSQL 数据库中,我可以获得正确的图像。获得所有图像后,我想将它们显示在 ion-img 标签中(来自 ionic 框架)
代码信息
所以我使用的是 PostgreSQL 使用 在 javascript 中使用后端的数据库express.js 库和前端 Angular .
这是我在 postgreSQL 中的表--> table postgreSQL
在我的 后端 index.js 文件我有这个代码

 app.get(
  "/getMarkerPhotos/:straatnaam/:straatnr/:postcode",
  function (req, res) {
    client.query(
      "select * from housee.houses_images where straatnaam = $1 AND straatnr = $2 AND postcode = $3",
      [req.params.straatnaam, req.params.straatnr, req.params.postcode],
      function (err, data) {
        if (err != null) {
          res.sendStatus(500);
        } else {
          res.sendStatus(200);
        }
      }
    );
  }
);
后端的调用正在工作,因为如果我在 postman 中运行它,它会以 JSON 格式返回我的数据 --> postman
到前端,在我的 中api.service.ts 文件我做了这个功能
getMarkerPhotos(straatnaam: any, straatnr: any, postcode: any): Observable<any> {
    var result = this.http.get(this.url + '/getMarkerPhotos/' + straatnaam + '/' + straatnr + '/' + postcode)
    .pipe(
      catchError(this.handleError)
   );
    console.log(result)
    return result
  }

<--other code-->

private handleError(error: HttpErrorResponse) {
    if (error.error instanceof ErrorEvent) {
      console.log(error.error.message)

    } else {
      console.log(error.status)
    }
    return throwError(
      console.log('Something is wrong!'));
  };
比在我的模态页面( maker-modal.components.ts )上我想显示数据库中的图像我有这个代码
ngOnInit() {
    this.getMarkerPhotos();
  }

  getMarkerPhotos() {
    this.api.getMarkerPhotos(this.straatnaam, this.straatnr, this.postcode).subscribe(

      data => {
        console.log(data)
        //this.photos.push(data)
        //console.log(this.photos)
      },
      error => {
        console.log("Subscribe error: " + error)
      }
    );
  }
我希望有人能帮我解决这个问题。
提前致谢!

最佳答案

更新 index.js

app.get(
  "/getMarkerPhotos/:straatnaam/:straatnr/:postcode",
  function (req, res) {
    client.query(
      "select * from housee.houses_images where straatnaam = $1 AND straatnr = $2 AND postcode = $3",
      [req.params.straatnaam, req.params.straatnr, req.params.postcode],
      function (err, data) {
        if (err != null) {
          res.sendStatus(500);
        } else {
          res.send({data});
        }
      }
    );
  }
);

关于javascript - 尝试获取多个图像时,Angular observable 抛出错误,状态代码为 200,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67697022/

相关文章:

angular - 不推荐使用 FormBuilder 组

Angular Testing HostListener

javascript - 创建 TCP 服务器时连接的标识符是什么?

javascript - 为什么这里似乎需要分号?

javascript - 使用过滤器返回对象值匹配的数组

sql - 使用限制的 Sequelize 分页需要 4 倍的时间来加载。我该如何优化?

c# - 在单引号中设置参数值的Postgres准备语句错误

javascript - 读取跨站点 iframe 位置

javascript - 来自另一个组件的 Angular2 调用函数

postgresql - 主机上的 Docker Postgres 数据量