Error: During file upload to S3 from Angular app

0

Hi,

I am trying to upload a file to S3 using the aws-sdk for Angular. Following is the code snippet:

const credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'xxxx-xxx'
});
AWS.config.update({
region: 'xxxx',
credentials: credentials
});

const params = {  
  Bucket: 'xxxx',  
  Key: file.name,  
  Body: file  
};  

const bucket = new S3({  
  apiVersion: '2006-03-01',  
});  

bucket.upload(params, function (err, data) {  
  if (err) {  
    console.log('Error uploading file: ', err);  
  } else {  
    console.log('Successfully uploaded file', data);  
  }  
});  

When I upload a file and click on submit, I encounter the following error:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'Stream' of undefined
TypeError: Cannot read property 'Stream' of undefined
at Object.computeSha256 (VM163 vendor.js:90869)
at Request.COMPUTE_SHA256 (VM163 vendor.js:82274)
at Request.callListeners (VM163 vendor.js:87118)
at Request.emit (VM163 vendor.js:87094)
at Request.emit (VM163 vendor.js:85728)
at Request.transition (VM163 vendor.js:85067)
at AcceptorStateMachine.runTo (VM163 vendor.js:90122)
at VM163 vendor.js:90134
at Request.<anonymous> (VM163 vendor.js:85083)
at Request.<anonymous> (VM163 vendor.js:85730)
at resolvePromise (VM161 polyfills.js:3170)
at new ZoneAwarePromise (VM161 polyfills.js:3252)

Can anyone help me out with this?

asked 5 years ago316 views
1 Answer
0

I figured out the issue. We need to add the following snippet to polyfills.ts

(window as any).process = { browser: true };
answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions