amazon-s3 - 使用 Clojure 的 Amazonica 创建 S3 签名 URL 时如何指定 ACL 策略?
问题描述
我正在尝试使上传的 ACL 为public-read
. Amazonica的文档非常薄,经过数小时的修修补补,我还没有弄清楚如何实现这一目标。简而言之,我不知道如何让它签署标题。
服务器端,我的代码如下所示。
(s3/generate-presigned-url
creds
{:bucket-name "mybucket"
:method "PUT"
:expires 10000
:key "my-key"
:cache-control "max-age=31557600;"
:request-parameters {:x-amz-acl "public-read"}
})
客户端,我获取创建并执行 XHR PUT 请求的 URL
var xhr = new XMLHttpRequest();
xhr.open("PUT", signedUrl);
xhr.setRequestHeader('Cache-Control', 'max-age=31557600')
xhr.onload = ...
xhr.onerror = ...
xhr.send(file);
这完美地工作,除了它有错误的ACL:“私人”而不是“公共”
添加它的客户端很容易
var xhr = new XMLHttpRequest();
xhr.open("PUT", signedUrl);
xhr.setRequestHeader('Cache-Control', 'max-age=31557600')
xhr.setRequestHeader('x-amz-acl', 'public-read')
xhr.onload = ...
xhr.onerror = ...
xhr.send(file);
但是由于HeadersNotSigned
. 我根本不知道如何在服务器端添加它以便他们得到签名。该SignedHeaders
部分从不包含任何附加参数。
我盲目地尝试过各种组合
(s3/generate-presigned-url
creds
{:headers {:x-amz-acl "public-read"}
:x-amz-acl "public-read"
:metadata {:x-amz-acl "public-read"}
:signed-headers {:x-amz-acl "public-read"}
:amz-acl "public-read"
:x-amz-signed-headers {:x-amz-acl "public-read"}
:X-Amz-SignedHeaders ["x-amz-acl"]
:request-parameters {:x-amz-acl "public-read"}
})
如何将 ACL 策略添加到签名的 url?
解决方案
我对此没有直接的答案,但有一个解决方法供您考虑:将 s3 存储桶中的所有对象默认为公开读取。
您可以通过将此存储桶策略添加到您的存储桶来做到这一点(bucketnm
当然要替换):
{
"Id": "Policy1397632521960",
"Statement": [
{
"Sid": "Stmt1397633323327",
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::bucketnm/*",
"Principal": {
"AWS": [
"*"
]
}
}
]
}
推荐阅读
- drake - 输入端口的索引是什么意思?
- kubernetes - 在 k8s 集群上运行的 ansible 的正确 dockerfile
- c# - 搜索字典值的字符串,然后用字典的键替换匹配的值?
- c++ - 计算树中大于输入名称的名称数量的函数
- authentication - 我正在尝试通过在应用程序之间共享 cookie(登录和网页)在 .net core 3.1 中实现 SSO
- shell - 使用shell脚本从hive查询结果中查找字符串并提取值?
- apache-spark - 从 Kafka 读取数据时如何优化 Spark Streaming 作业的延迟?
- c# - 如何从页面模型中的字节数组从 .net core razor 页面渲染 PDF
- reactjs - 发送数据 React 到 Node
- r - R:通过向量对矩阵进行索引,每行或列都有单独的索引