简体   繁体   中英

AWS S3 getObject JS SDK

I am using JS SDK 2.7.13 for AWS. I can not seem to getObject from S3 using a web browser.

i tried the code listed here

getS3Object(){

    AWS.config.region = 'us-east-1';

    AWS.config.update({
        credentials: new AWS.CognitoIdentityCredentials({
              IdentityPoolId: 'us-east-1:00000000-0000-0000-0000-000000000000'
        })
    });
    AWS.config.credentials.refresh(function(){

        let s3 = new AWS.S3({region: 'us-east-1', params: {Bucket: 'BUCKET NAME'}});
        let params = {
            Bucket: 'BUCKET NAME',
            Key: "NAME OF FILE I WANT"
        };

        s3.getObject(params, function(err, data) {
            if (err) console.log(err, err.stack); // an error occurred
            else     console.log(data);           // successful response
        });
    });
}

I get

Error: Missing credentials in config

and

"NotAuthorizedException: Missing credentials in config

i can get the item if i use the url path but i also want to upload later on so i would need this to work.

You need to get temporary access credentials from AWS cognito and update AWS.config.credentials . Refer this link for more details.

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