简体   繁体   中英

Issue with uploading Image to Amazon S3 Bucket from Angular app

I am trying to upload a base64 image from Angular app to Amazon S3 bucket. Following is the code I am using.

uploadAssets(base64File, assetType, fileName, file) {

const AWSService = AWS;
const region = ""
const bucketName = "";
const identityPoolId = "";
const accessKeyId = "";
const secretAccessKey = "";


AWSService.config.update({
    region: region,
    accessKeyId: accessKeyId,
    secretAccessKey: secretAccessKey,
    credentials: new AWSService.CognitoIdentityCredentials({
    IdentityPoolId: identityPoolId
    })
});

const s3 = new AWSService.S3({
    apiVersion: '',
});

var objKey = bucketName+ "/" + fileName;
var params = {
    Key: objKey,
    ContentType: file.type,
    Bucket: bucketName,
    Body: base64File,
    ContentEncoding: 'base64',
    ACL: 'public-read'
};

s3.upload(params, function (err, data) {
    if (err) {
        console.log(err, 'there was an error uploading your file');
    } else {
        console.log(data);
    }
});

}

For some reason, I am getting the following error

TypeError: Cannot read property 'byteLength' of undefined

Am I missing something here?

It worked for me when I changed secretAccessKey to secretKey

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