Skip to content

Instantly share code, notes, and snippets.

@wKoza

wKoza/upload.ts Secret

Created August 10, 2017 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wKoza/d10b051756badd39b418642d2006da42 to your computer and use it in GitHub Desktop.
Save wKoza/d10b051756badd39b418642d2006da42 to your computer and use it in GitHub Desktop.
const req = new HttpRequest('POST', '/upload/article', file, {
reportProgress: true,
});
http.request(req).subscribe(event => {
// you get now access to the raw event stream.
if (event.type === HttpEventType.UploadProgress) {
// This is an upload progress event. Compute and show the % done:
const percentDone = Math.round(100 * event.loaded / event.total);
console.log(`File is ${percentDone}% uploaded.`);
} else if (event instanceof HttpResponse) {
console.log('File is completely uploaded!');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment