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?

posta 5 anni fa421 visualizzazioni
1 Risposta
0

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

(window as any).process = { browser: true };
con risposta 5 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande