我试图从浏览器上传数据到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