【问题标题】:Amazon S3 Signed Url is not working with Office Web Apps Viewer (encodeURIComponent not working)Amazon S3 签名 URL 不适用于 Office Web Apps 查看器(encodeURIComponent 不起作用)
【发布时间】:2020-05-04 23:27:56
【问题描述】:

我正在尝试使用 iframe 标记嵌入“Office Web Apps Viewer”以在我的网站上显示电子表格预览。我尝试使用 encodeURIComponent 对 url 进行编码,但它显示“我们正在获取您的文件”加载栏,但没有任何反应。提前致谢。

const originalUrl ="https://exampleDomain.amazonaws.com/Folder/Filename.xlsx?algorithm=algorithmName&credential=region&date=date&expires=time&token=encryptedToken&signature=encryptedSignature&headers=example"
const encodedUrl = encodeURIComponent(originalUrl);
const iFrameUrl = `https://view.officeapps.live.com/op/embed.aspx?src=${encodedUrl}`;
<iframe title="l" src={iFrameUrl} style={{ maxHeight: 'auto', maxWidth: 'auto'}} />

注意:上面的代码可以通过替换 src = https://docs.google.com/viewer?url=yourUrl&embedded=true 与 google 文档一起使用

【问题讨论】:

  • 你有没有检查你的浏览器控制台,看看有没有什么可看的?您是否检查过 S3 存储桶日志以查看是否正在发生访问尝试但参数错误?
  • 我们也面临这个问题。签名的 s3 URL 不起作用。谁有解决办法?
  • 我有同样的问题,但使用的是谷歌云存储。我相信 Office Web Apps 查看器可以轻松处理 URL。 stackoverflow.com/questions/61815774/…

标签: javascript amazon-s3 office365 ms-office


【解决方案1】:

我也遇到了这个问题,所以我做了一些挖掘。如果 URL 中有任何 GET 变量,它似乎会失败。一个想法跳到脑海中,使用 URL 重定向来屏蔽 S3 URL,并且这很有效。 (我使用bit.ly 创建了一个没有任何GET 变量的重定向)

显然,这不是一个出色的解决方案,但它确实有效。如果您拥有服务器,则可以创建自己的后端来生成这些不包含 GET 变量的 URL。

然后您可以生成以下格式的 URL:

https://example.com/api/s3request/s3_domain_path/get_param_1/getparam_2/get_param_3/etc/

这将返回重定向到:

https://s3_domain_path?X-Amz-Security-Token=get_param_1&amp;X-Amz-Algorithm=get_param_2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-22
    • 2018-05-24
    • 2021-03-17
    • 2017-11-26
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多