2017-07-20 48 views
0

我試圖上傳一張照片到我的桶。我已經使用boto3生成了STS accesskey和secretykey和會話令牌。AWS javascript sdk無法上傳到s3使用STS憑據

AWS.config.update({ accessKeyId: aws_cred.access_key, secretAccessKey: aws_cred.secret_key, sessionToken: aws_cred.session_token }); 

var unique_key = "files101/" + file.name; 

var params = { Key: unique_key, ContentType: file.type, Body: file, ACL: 'public-read' }; 

bucket.upload(params, opts, function(err, data) { 
    if(err) { 
       console.log(err); 
       return 0; 
      } 
}); 

我得到了仍然有此錯誤

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9999' is therefore not allowed access. 

即使我已經添加ACL來我鬥

enter image description here

我有這個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> 
    <AllowedMethod>DELETE</AllowedMethod> 
    <MaxAgeSeconds>3000</MaxAgeSeconds> 
    <ExposeHeader>x-amz-meta-custom-header</ExposeHeader> 
    <ExposeHeader>ETag</ExposeHeader> 
    <AllowedHeader>*</AllowedHeader> 
</CORSRule> 
</CORSConfiguration> 

任何人都可以幫助我?謝謝

回答

0

當您將CORS配置添加到存儲桶時,通常會修復此錯誤。 以下是一些其他解決方法的好回答。

https://stackoverflow.com/a/19939041/5358917

+0

林不知道這個錯誤是關於我的CORS。使用我的實際密鑰而不是STS生成的密鑰時,我的上傳工作正常。 – ParTidA

相關問題