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?

已提問 5 年前檢視次數 350 次
1 個回答
0

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

(window as any).process = { browser: true };
已回答 5 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南