[英]Aws-sdk s3 upload CORS error cause by CacheControl Option
My code is looks like this and when我的代码看起来像这样,什么时候
import { FileUpload } from "../types/scalars/Upload.scalar";
new S3.ManagedUpload({
params: {
ACL: "public-read",
Bucket: process.env.AWS_BUCKETNAME || "",
Body: upload.createReadStream(),
Key: filename || upload.filename,
CacheControl: "max-age=604800,public,immutable",
},
// tags,
}).promise();
If I upload this with the CacheControl option, upload works fine.如果我使用 CacheControl 选项上传它,上传工作正常。
But when I load it on the client side I get a CORS error.但是当我在客户端加载它时,出现 CORS 错误。
If I remove CachControl, obviously the CORS error doesn't come up.如果我删除 CachControl,显然不会出现 CORS 错误。
My Bucket has CORS-Policy like this我的桶有这样的 CORS-Policy
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"POST"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]
Headers with CacheControl Param带有 CacheControl 参数的标头
Headers without CachControl Param没有 CachControl 参数的标头
With CacheControl param, My Allow headers are gone.有了 CacheControl 参数,My Allow 标头就消失了。 Why is that?
这是为什么?
I found some documents in herehttps://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9我在这里找到了一些文件https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
I had same problem.我有同样的问题。
Did you set bucket policy in Amazon S3 actions?您是否在 Amazon S3 操作中设置了存储桶策略?
https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-with-s3-actions.html https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-with-s3-actions.html
It worked by setting policy in my project.它通过在我的项目中设置策略来工作。
And you can check if settings works by using curl.您可以使用 curl 检查设置是否有效。
The below command is check if POST request can access to a bucket.以下命令检查 POST 请求是否可以访问存储桶。
curl -i https://your-bucket-name.s3.your-bucket-region.amazonaws.com/index.html -H "Access-Control-Request-Method: POST" -X OPTIONS -H "Origin: http://localhost:3000"
Check this link out.检查此链接。
https://aws.amazon.com/jp/premiumsupport/knowledge-center/s3-configure-cors/ https://aws.amazon.com/jp/premiumsupport/knowledge-center/s3-configure-cors/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.