【问题标题】:Open S3 Pre-Signed URL with window.location not working打开 S3 预签名 URL,window.location 不起作用
【发布时间】:2018-02-09 05:29:42
【问题描述】:

我试图在我的 react 应用程序中显示来自 AWS S3 预签名 URL 的图像或文档。以下是我的代码。

this.props.getS3SignedURL(key).then(url=> {
    this.setState({ isLoading: false, error: "", url: url});
    window.location = url;
}, err => {
    //err
});

它在谷歌浏览器中没有任何问题,它会显示文档。但在 Microsoft Edge 和 IE 中,位置不会改变。

我尝试了 encodeURI()、encodeURIComponent() 和 window.location.href 所有组合。但不能让它在 Edge 和 IE 中工作。如here 所述,我尝试使用谷歌文档查看器。仍然无法正常工作,我怀疑我是否可以使用 Google 文档查看器,因为来自 url 的文档可以是图像/pdf/xls 等。

【问题讨论】:

  • 它是否返回任何错误?还是只是不显示文档?
  • 错误是:未处理的承诺拒绝错误:发生安全问题。当我输入 window.location="s3-presigned-url" 它说权限被拒绝。对于像 google.com 这样的其他网址,它可以完美运行。

标签: reactjs internet-explorer amazon-s3 microsoft-edge


【解决方案1】:

根据您对未处理的承诺拒绝的评论,我建议您尝试更常见的处理承诺错误的方法,如下所示:

this.props.getS3SignedURL(key)
  .then(url => {
    this.setState({ isLoading: false, error: "", url: url });
    window.location = url;
  })
  .catch(err => {
    console.log(err);
  });

除此之外,您可能需要检查这不是SOP 问题或CORS 问题。

【讨论】:

    猜你喜欢
    • 2021-03-19
    • 2021-12-28
    • 2020-08-22
    • 2014-09-01
    • 1970-01-01
    • 2018-12-27
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    相关资源
    最近更新 更多