Tho there are many adhoc libraries supporting upload/download progress in angular2, I do not know how to do use native angular2 http api to show progress while doing upload/download.
The reason why I want to use native http api is because I want to utilise
- http interceptors(http API wrappers) around native http api that validate, cache & enrich the actual http request being sent such as this & this
- Besides angular's http api is much more robust than any adhoc APIs
There is this nice article about how to do upload/download using angular's http api
But the article mentions that there is no native way to support progress.
Did anyone try using http api for showing progress?
If not, do you know an issue in the angular repo for this?
I would suggest using the native JavaScript XHR wrapped as an Observable, it's fairly easy to create on your own:
And this is how one would use it:
As of Angular 4.3.x and beyond versions, it can be achieved using the new HttpClient from
@angular/common/http
.Read the Listening to progress events section.
Simple upload example (copied from the section mentioned above):
And for downloading, it might be something like pretty much the same:
Remember in case that you're monitoring a download, the
Content-Length
has to be set, otherwise, there's no way to the request to be measured.