Amazon s3 使用Clojure';创建S3签名URL时,如何指定ACL策略;是亚马逊吗?
我正在尝试使上载的ACL为Amazon s3 使用Clojure';创建S3签名URL时,如何指定ACL策略;是亚马逊吗?,amazon-s3,clojure,amazonica,Amazon S3,Clojure,Amazonica,我正在尝试使上载的ACL为public read。这些文档非常薄,经过几个小时的修补,我还没有找到实现这个目标的方法。简而言之,我不知道如何让它在标题上签名 服务器端,我的代码如下所示 (s3/generate-presigned-url creds {:bucket-name "mybucket" :method "PUT" :expires 10000 :key
public read
。这些文档非常薄,经过几个小时的修补,我还没有找到实现这个目标的方法。简而言之,我不知道如何让它在标题上签名
服务器端,我的代码如下所示
(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是错误的:“private”而不是“public”之外,它工作得很好
在客户端添加it很容易
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);
但是由于标题未签名
,请求当然会失败。我根本不知道如何将it添加到服务器端,以便它们得到签名。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 bucket中的所有对象默认为public read 您可以通过将此bucket策略添加到您的bucket中来实现这一点(当然,替换
bucketnm
):
{
"Id": "Policy1397632521960",
"Statement": [
{
"Sid": "Stmt1397633323327",
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::bucketnm/*",
"Principal": {
"AWS": [
"*"
]
}
}
]
}