简体   繁体   中英

AWS javascript sdk can't upload to s3 using STS credentials

Im trying to upload a photo to my bucket. I already generate a STS accesskey and secreykey and session token using boto3.

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;
            }
});

I got still got this error

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

even if I already added ACL to my bucket

在此处输入图片说明

I have this 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>

Anyone can help me?. thanks

This error usually fix when you add CORS configuration into your bucket. Here is a good answer with some other workarounds.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM