1

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?

3
  • Where is the error coming from? Is it from the s3 library? Is it from a network request? Is it in your code? It sounds like you're passing an undefined value to something expecting a stream. Commented Dec 12, 2018 at 21:09
  • The error is coming from s3 library. The .upload functions receive an error. I have done similar stuff on Node.js, however on Angular I receive an error Commented Dec 12, 2018 at 21:13
  • did you fix it? I'm having the same issue. Commented Dec 28, 2018 at 14:28

1 Answer 1

1

It worked for me when I changed secretAccessKey to secretKey

Sign up to request clarification or add additional context in comments.

1 Comment

Where did this idea come from?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.