【问题标题】:Angular read json file from s3从 s3 角度读取 json 文件
【发布时间】:2020-12-13 20:21:09
【问题描述】:

我尝试从具有公共访问权限的 s3 存储桶中读取 json 文件数据以解析数据并显示在 html 表中。

http.get<Post>('https://jsonfile/file.json').subscribe    (res => {   
      console.log(res);
    });

我有这个错误:

ERROR
HttpErrorResponse {headers: {…}, status: 0, statusText: "Unknown Error", url: null…}

这是我的堆栈闪电战:https://stackblitz.com/edit/angular-kwn1zg

【问题讨论】:

    标签: angular typescript


    【解决方案1】:

    这很可能是由于 CORS 问题。在this answer 中查找更多信息。

    如果您使用此 URL,它可以工作:

    https://cors-anywhere.herokuapp.com/https://temporal.s3.amazonaws.com/limites.json

    http
      .get<Post>("https://cors-anywhere.herokuapp.com/https://temporal.s3.amazonaws.com/limites.json")
      .subscribe(res => {
        console.log(res);
      });
    

    因此,您必须为 S3 存储桶启用 CORS 才能正确解决此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      • 1970-01-01
      • 2019-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-29
      相关资源
      最近更新 更多