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?

gefragt vor 5 Jahren350 Aufrufe
1 Antwort
0

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

(window as any).process = { browser: true };
beantwortet vor 5 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen