简体   繁体   English

通过 iframe 从 S3 存储桶嵌入 HTML 页面无法加载资源和媒体文件

[英]Embedded HTML page from S3 bucket via iframe can't load resources and media files

We have an s3 bucket where we have multiple folders with different small projects that contain basic, static webpages with an index.html entry point.我们有一个 s3 存储桶,其中有多个包含不同小项目的文件夹,这些项目包含基本的 static 网页和index.html入口点。 The plan is to integrate those static pages within a react-app through an iframe. When we do that with an example page, the embedding of the HTML document works but none of the resources get loaded (image files + stylesheets), throwing the following error:计划是通过 iframe 将这些 static 页面集成到 react-app 中。当我们使用示例页面执行此操作时,HTML 文档的嵌入有效但没有加载任何资源(图像文件 + 样式表),抛出以下内容错误:

DOMException: Blocked a frame with origin "BUCKET-DOMAIN" from accessing a cross-origin frame.

When looking up that error I usually find people trying to control some parts of the document rendered within the iframe using the postMessage API. In my case however I only want to make sure that the iframe embeds the website as it is shown on the publically available link with all resources.在查找该错误时,我通常会发现人们试图使用postMessage API 来控制在 iframe 中呈现的文档的某些部分。然而,在我的例子中,我只想确保 iframe 嵌入了网站,因为它在公开可用的网站上显示链接所有资源。

I've tried making the S3 bucket specifically serve just one static website, thinking that this might influence the way the embedding works.我试过让 S3 存储桶专门为一个 static 网站提供服务,认为这可能会影响嵌入的工作方式。 However it's still the same problem.然而,它仍然是同样的问题。 Pretty sure there's a very simple solution to this and something I'm overlooking.很确定对此有一个非常简单的解决方案和我忽略的东西。 One potential option would be to give the S3 bucket a subdomain on our site, but I don't see how that would work for example in local development.一种可能的选择是在我们的站点上为 S3 存储桶提供一个子域,但我不知道这在本地开发中如何工作。

If you bucket is public then you can access with your cdn link.如果您的存储桶是公开的,那么您可以使用您的 cdn 链接访问。 Otherwise You will configure it with aws sdk. I think this link will help you否则,您将使用 aws sdk 对其进行配置。我认为此链接会对您有所帮助

Access files stored on Amazon S3 through web browser 通过 web 浏览器访问存储在 Amazon S3 上的文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM