问题描述
限时送ChatGPT账号..我正在尝试设置一个 s3 存储桶,以便我的 Django 应用程序可以上传和抓取用户媒体文件.我已经参与了此视频 https://www.youtube 中的部分/watch?v=kt3ZtW9MXhw&t=224s 设置 cors 策略的位置.
在本教程中,他使用 XML,但 aws 现在需要 json.我不知道该放什么.我希望我的网站能够进行 GET、PUT、POST、PATCH 和 DELETE.
我的应用是一个托管在 Digital Ocean 液滴上的 Django 应用
我找到了一个例子,我已经编辑并添加到我的配置中
<预><代码>[{允许的标题":[*"],允许的方法":[放置",邮政",删除"],允许的起源":[http://www.example1"],ExposeHeaders":[]},{允许的标题":[*"],允许的方法":[放置",邮政",删除"],允许的起源":[http://www.example2"],ExposeHeaders":[]},{允许的标题":[],允许的方法":[获取"],允许的起源":[*"],ExposeHeaders":[]}] 解决方案用于配置 cors:-
您需要授予对存储桶的公共访问权限.
(通过存储桶策略和控制台) https://stackoverflow/a/4709391/13126651(用于公共访问存储桶策略)确保将您的存储桶用作网站,然后在您的存储桶 cors 设置下附加此策略.<预><代码>[{允许的标题":[授权"],允许的方法":[获取"],允许的起源":[<第一个桶的 url,带有 http://...末尾没有斜线>";],ExposeHeaders":[],MaxAgeSeconds":3000}]
I'm trying to set up an s3 bucket so my Django app can upload and grab user media files. I've come to the part in this video https://www.youtube/watch?v=kt3ZtW9MXhw&t=224s where you set the cors policy.
In this tutorial he uses XML but aws now wants json. I don't know what to put. I want my website to be able to GET, PUT, POST, PATCH and DELETE.
My app is a Django app hosted on a Digital Ocean droplet
Edit: I've found an example which I've edited and added to my config
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"http://www.example1"
],
"ExposeHeaders": []
},
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"http://www.example2"
],
"ExposeHeaders": []
},
{
"AllowedHeaders": [],
"AllowedMethods": [
"GET"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]
解决方案
For configuring cors:-
you need to givepublic access to bucket.
( through bucket policy and
console) https://stackoverflow/a/4709391/13126651 ( for public access bucket policy)
make sure to enable your bucket to be used as website and then attach this policy, under your bucket cors setting.
[
{
"AllowedHeaders": [
"Authorization"
],
"AllowedMethods": [
"GET"
],
"AllowedOrigins": [
"<url of first bucket with http://...without slash at the end>"
],
"ExposeHeaders": [],
"MaxAgeSeconds": 3000
}
]
这篇关于S3 存储桶 CORS 策略 Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论