0

I am building out a media uploader for my company in Angular 6, and loading files into our bucket in s3. So far, the files are uploading successfully and showing up in the s3 console, but the POST request always returns 'null', even if it works.

I want to get response data back because I'm trying to keep track of the progress for uploads, to show the user in the UI. But I'm unable to grab any events from a null response.

This is how the working code currently looks. When I add a console.log and check the response it is 'null'. Am I doing anything wrong, or is s3 the problem here?

upload(url: string, data: any) {
  const options = { reportProgress: true };

  return this.http.post(url, data, options)
    .map((response: Response) => response);
}
jtbitt
  • 561
  • 1
  • 5
  • 18
  • 1
    duplicate question of https://stackoverflow.com/questions/51176537/angular-6-and-node-js-aws-s3-file-upload-progress-bar ?? please check if it helps you – jcuypers Feb 23 '19 at 03:06
  • 1
    That thread was a big help. Thank you! – jtbitt Feb 23 '19 at 03:20

2 Answers2

5

Adding observe: 'events' to the options resolved the issue. I am now seeing the progress being returned.

const options = { reportProgress: true, observe: 'events' };
jtbitt
  • 561
  • 1
  • 5
  • 18
0

It's worked to me as expected

    return this.http.post(url, formData, {
      reportProgress: true,
      observe: 'events'
    });
monks
  • 35
  • 5