[英]Getting a 403 AccessDenied uploading a file to S3 only when using public-read ACL
我正在嘗試對圖像數據進行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
]
原來,我正在使用其憑據的用戶需要設置一個策略,以使我能夠使用public-read
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.