ブラウザから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を使用して)であると私はバケットにCORSをオンに設定している
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)
です:
<?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>
しかし、私はまだ403の応答を禁止されています。アップロードしようとしている画像は「photo.png」です。私はここに何かを逃していますか
ありがとう、これはまさに問題でした。 – wazzaday