简体   繁体   English

如何让我的 HTML 文件访问 Amazon S3 存储桶中的 CSS 和 JavaScript 文件?

[英]How can I get my HTML file to access my CSS and JavaScript files in an Amazon S3 Bucket?

I am currently trying to host an html file as a website on AWS S3 to get around the CORS Policy.我目前正在尝试在 AWS S3 上托管一个 html 文件作为网站来绕过 CORS 策略。 When I put all of my documents into a new bucket, the html file opens without accessing the css or javascript that is in the bucket with it.当我将所有文档放入一个新存储桶时,html 文件打开时不会访问存储桶中的 css 或 javascript。 When I open the file outside of the bucket (ie from my computer).当我在存储桶外(即从我的计算机)打开文件时。 The page opens with all the css and javascript working.该页面打开时所有 css 和 javascript 都在工作。 I am wondering how I can get my css and javascript working within the bucket.我想知道如何让我的 css 和 javascript 在存储桶中工作。

There are a few ideas I have that might help with the problem, but I have no idea how to implement them.我有一些想法可能有助于解决问题,但我不知道如何实施它们。 I'm not sure if there are extra permissions I must grant to my files to allow them to access each other.我不确定是否有额外的权限必须授予我的文件以允许它们相互访问。 I'm also not sure if there is something within the code of the html file that must change.我也不确定 html 文件的代码中是否有必须更改的内容。 Any help is much appreciated!任何帮助深表感谢!

You can use static webhosting for a s3 bucket see [1].您可以对 s3 存储桶使用静态虚拟主机,请参阅 [1]。

Otherwise it is just a data container, where you load a file form and Context with referenced files is not matched to the bucket + path directly - I guess.否则,它只是一个数据容器,您可以在其中加载文件表单,并且带有引用文件的上下文与存储桶 + 路径不直接匹配 - 我猜。

I unfortunately don't have better explanation at the moment.不幸的是,我目前没有更好的解释。

Alternatively if the files are publicly available you could maybe also provide the full paths to the files in the bucket within the html.或者,如果文件是公开可用的,您也可以在 html 中提供存储桶中文件的完整路径。

But that is not very nice or maintainable (if it even works).但这不是很好或可维护(如果它甚至有效)。

[1] https://docs.aws.amazon.com/en_en/AmazonS3/latest/user-guide/static-website-hosting.html [1] https://docs.aws.amazon.com/en_en/AmazonS3/latest/user-guide/static-website-hosting.html

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

相关问题 如何让用户通过我的自定义域访问亚马逊s3 html / javascript页面? - How can I let users visit amazon s3 html/javascript pages through my custom domain? 使用HTML5 / JavaScript访问Amazon S3上的文件 - Access files on Amazon S3 using HTML5 / JavaScript Amazon S3 JavaScript和CSS文件403 - Amazon S3 javascript and css files 403 如何在浏览器中告诉我s3操作已完成并且存储桶的状态是一致的? - How can I tell, in the browser, that my s3 operation has completed and the state of my bucket is consistent? 可以授予对我的 Amazon S3 存储桶中某些对象的公共读取访问权限吗? - is it okay grant public read access to some objects in my Amazon S3 bucket? 如何将 Amazon S3 存储桶中的 javascript 连接到 Amazon 时间服务器? - How to connect javascript in Amazon S3 bucket to Amazon time server? 在使用JavaScript SDK for Amazon S3创建存储桶到我的实时存储库时出错 - Getting error while using the javascript Sdk for amazon s3 to Create bucket to my live repository 在 Promise 中获取存储桶中的所有 Amazon S3 文件 - Get all Amazon S3 files inside a bucket within Promise Javascript从亚马逊s3存储桶下载文件? - Javascript to download a file from amazon s3 bucket? 如何通过 JavaScript 访问 S3 存储桶? - How to access S3 bucket through JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM