我試圖從瀏覽器上傳數據到s3存儲桶。我已經生成了預先簽名的url,但是我得到了403禁止的回覆。S3從瀏覽器上載帶有預簽名url的圖片
我的服務器代碼是
const s3 = new AWS.S3({
accessKeyId: settings.resourceBucketKey,
secretAccessKey: settings.resourceBucketSecret,
region: 'eu-west-1'
})
const params = {
Bucket: 'my-bucket',
Key: 'photo.png',
ContentType: 'image/png',
ACL: 'authenticated-read',
}
const url = s3.getSignedUrl('putObject', params)
console.log(url)
我的客戶端代碼(使用生成的URL)
const input = $('#myinput')
input.on('change', (res) => {
var theFormFile = $('#myinput').get()[0].files[0];
$.ajax({
url: url,
type: 'PUT',
contentType: 'image/png',
processData: false,
data: theFormFile,
}).success(function(){
alert('success')
})
}, false)
我已經設置CORS上的水桶:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
但我的答覆仍然被禁止。我想上傳的圖片叫'photo.png'。我在這裏錯過了什麼嗎?
謝謝你正是這個問題! – wazzaday