javascript - Amazon S3 签名 URL 无法与 Office Web Apps 查看器配合使用(encodeURIComponent 无法使用)

标签 javascript amazon-s3 office365 ms-office

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

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 与谷歌文档一起工作

最佳答案

我也刚遇到这个问题,所以我做了一些挖掘。如果有任何 GET,它似乎失败了URL 中的变量。一个关于使用 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&X-Amz-Algorithm=get_param_2

关于javascript - Amazon S3 签名 URL 无法与 Office Web Apps 查看器配合使用(encodeURIComponent 无法使用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59798131/

相关文章:

javascript - chess.js 的 Typescript 声明文件

php - 我应该如何设计我的应用程序以便轻松提供多种语言?

python - Django 如何循环对象并在模板中显示变量

python - 通过django storages boto s3将二进制数据保存到模型上的文件中

ios - Microsoft Graph API : Get Files List API, 给出空数组

javascript - 从 JavaScript 使用 Office 365 上的 REST 远程访问 Sharepoint 2013

sharepoint - 为什么我的 SharePoint 网站站点地图会回滚?

javascript - 每天更新网站变量

javascript - AWS CloudFront 中的单页应用程序

用于更改非必填字段值的 Javascript