我正在尝试对图像数据进行POST(使用JavaScript从浏览器直接进行)。如果我使用private
ACL,一切正常,但如果我将其更改为public-read
,我会收到403回复,邮件为AccessDenied
。
acl
属性与我发送的acl
表单参数相匹配。SignatureDoesNotMatch
回复。任何可能导致这种情况的想法?
根据要求,这里是我正在使用的代码(在我开始工作后需要整理一下):
.directive 's3ImageUploader', ['$http', '$filter', ($http, $filter) ->
replace: true
restrict: 'E'
scope: true
template: '<input type="file" name="image" class="form-control input-lg">'
link: ($scope, $element) ->
awsAccessKeyId = '...'
secret = '...'
bucket = '...'
folder = '...'
policy =
expiration: '2020-12-01T12:00:00.000Z'
conditions: [
{bucket: bucket}
['starts-with', '$key', '']
{acl: 'public-read'}
['starts-with', '$Content-Type', 'image/']
]
policyBase64 = $filter('base64') policy
signature = $filter('hmacSha1') policyBase64, secret
$element.on 'change', ->
file = $element.get(0).files[0]
key = "#{folder}/#{new Date().getTime()}-#{file.name}"
formData = new FormData()
formData.append 'key', key
formData.append 'acl', 'public-read'
formData.append 'Content-Type', file.type
formData.append 'AWSAccessKeyId', awsAccessKeyId
formData.append 'policy', policyBase64
formData.append 'signature', signature
formData.append 'file', file
$http.post "https://#{bucket}.s3.amazonaws.com/", formData,
headers:
'Content-Type': `undefined`
transformRequest: (data) -> data
]
答案 0 :(得分:1)
事实证明,我使用其凭据的用户需要设置一个策略,以便我使用public-read