我正在尝试使用 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/