File Upload using Angular 8 and Node.js example

In this tutorial, I will show you way to build Angular 8 with Node.js Express: File/Image upload & download example.

Other versions:
Angular 10 upload file/image to Node.js Server example
Angular 11 upload file/image to Node.js Server example

More Practice:
Angular 8 + Node.js Express + MySQL: CRUD example
Angular 8 + Node.js Express + PostgreSQL: CRUD example
Angular 8 + Node.js Express + MongoDB: CRUD example
Angular 8+ Node.js Express: JWT Authentication & Authorization example
Server side Pagination with Node.js and Angular 11/10/8


We’re gonna create a full-stack Angular 8 File/Image upload to Node.js Express Server in that user can:

  • see the upload process (percentage)
  • view all uploaded files/images
  • download by clicking on the file name


All uploaded files will be saved in uploads folder:


If you want to upload multiple files/images at once like this:


You can find the instruction here:
Angular 8 upload Multiple Images with Web API example



  • express 4.17.1
  • multer 1.4.2
  • cors 2.8.5


  • Angular 8
  • RxJS 6
  • Bootstrap 4

Node.js Express Rest APIs for File Upload & Storage

Node.js Server will provide APIs:

POST/uploadupload a File
GET/filesget List of Files (name & url)
GET/files/[filename]download a File

This is the project structure:


resources/static/assets/uploads: folder for storing uploaded files.
middleware/upload.js: initializes Multer Storage engine and defines middleware function to save uploaded files in uploads folder.
file.controller.js exports Rest APIs: POST a file, GET all files’ information, download a File with url.
routes/index.js: defines routes for endpoints that is called from HTTP Client, use controller to handle requests.
server.js: initializes routes, runs Express app.

You can find Step by Step to implement the Node.js Express Server (with Github) at:
Node.js Express File Upload Rest API example using Multer

Setup Angular 8 App for upload File

Let’s open cmd and use Angular CLI to create a new Angular Project as following command:

ng new Angular8UploadFile
? Would you like to add Angular routing? No
? Which stylesheet format would you like to use? CSS

We also need to generate some Components and Services:

ng g s services/UploadFile
ng g c components/UploadFiles

Now you can see that our project directory structure looks like this.

Angular Project Structure


Let me explain it briefly.

– We import necessary library, components in app.module.ts.
upload-file.service provides methods to save File and get Files from Node.js Server.
upload-files.component contains upload form, progress bar, display of list files.
app.component is the container that we embed all components.
index.html for importing the Bootstrap.

Set up App Module

Open app.module.ts and import HttpClientModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';

import { AppComponent } from './app.component';
import { UploadFilesComponent } from './components/upload-files/upload-files.component';

  declarations: [
  imports: [
  providers: [],
  bootstrap: [AppComponent]
export class AppModule { }

Add Bootstrap to the project

Open index.html and add following line into <head> tag:

<!DOCTYPE html>
<html lang="en">
    <link type="text/css" rel="stylesheet" href="" />

Create Angular Service for Upload Files

This service will use Angular HTTPClient to send HTTP requests.
There are 2 functions:

  • upload(file): returns Observable<HttpEvent<any>> that we’re gonna use for tracking progress
  • getFiles(): returns a list of Files’ information as Observable object


import { Injectable } from '@angular/core';
import { HttpClient, HttpRequest, HttpHeaders, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs';

  providedIn: 'root'
export class UploadFileService {

  private baseUrl = 'http://localhost:8080';

  constructor(private http: HttpClient) { }

  upload(file: File): Observable<HttpEvent<any>> {
    const formData: FormData = new FormData();

    formData.append('file', file);

    const req = new HttpRequest('POST', `${this.baseUrl}/upload`, formData, {
      reportProgress: true,
      responseType: 'json'

    return this.http.request(req);

  getFiles(): Observable<any> {
    return this.http.get(`${this.baseUrl}/files`);

FormData is a data structure that can be used to store key-value pairs. We use it to build an object which corresponds to an HTML form with append() method.

– We set reportProgress: true to exposes progress events. Notice that this progress event are expensive (change detection for each event), so you should only use when you want to monitor it.

– We call the request(PostRequest) & get() method of HttpClient to send an HTTP POST & Get request to the Node.js File Upload server.

Create Component for Upload Files

Let’s create a File Upload UI with Progress Bar, Card, Button and Message.

First we need to use the following imports:


import { Component, OnInit } from '@angular/core';
import { UploadFileService } from 'src/app/services/upload-file.service';
import { HttpEventType, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';

Then we define the some variables and inject UploadFileService as follows:

export class UploadFilesComponent implements OnInit {

  selectedFiles: FileList;
  currentFile: File;
  progress = 0;
  message = '';

  fileInfos: Observable<any>;

  constructor(private uploadService: UploadFileService) { }


Next we define selectFile() method. It helps us to get the selected Files.

selectFile(event) {
  this.selectedFiles =;

Next we define upload() method for upload file:

upload() {
  this.progress = 0;

  this.currentFile = this.selectedFiles.item(0);
    event => {
      if (event.type === HttpEventType.UploadProgress) {
        this.progress = Math.round(100 * event.loaded /;
      } else if (event instanceof HttpResponse) {
        this.message = event.body.message;
        this.fileInfos = this.uploadService.getFiles();
    err => {
      this.progress = 0;
      this.message = 'Could not upload the file!';
      this.currentFile = undefined;

  this.selectedFiles = undefined;

We use selectedFiles for accessing current File as the first Item. Then we call uploadService.upload() method on the currentFile.

The progress will be calculated basing on event.loaded and
If the transmission is done, the event will be a HttpResponse object. At this time, we call uploadService.getFiles() to get the files’ information and assign the result to fileInfos variable.

We also need to do this work in ngOnInit() method:

ngOnInit() {
  this.fileInfos = this.uploadService.getFiles();

Now we create the HTML template of the Upload File UI. Add the following content to upload-files.component.html file:

<div *ngIf="currentFile" class="progress">
    class="progress-bar progress-bar-info progress-bar-striped"
    attr.aria-valuenow="{{ progress }}"
    [ngStyle]="{ width: progress + '%' }"
    {{ progress }}%

<label class="btn btn-default">
  <input type="file" (change)="selectFile($event)" />

<button class="btn btn-success" [disabled]="!selectedFiles" (click)="upload()">

<div class="alert alert-light" role="alert">{{ message }}</div>

<div class="card">
  <div class="card-header">List of Files</div>
    class="list-group list-group-flush"
    *ngFor="let file of fileInfos | async"
    <li class="list-group-item">
      <a href="{{ file.url }}">{{ }}</a>

Add Upload File Component to App Component

Open app.component.html and embed the UploadFile Component with <app-upload-files> tag.

<div class="container" style="width:600px">
  <div style="margin: 20px">
    <h4>{{ title }}</h4>



import { Component } from '@angular/core';

  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
export class AppComponent {
  title = 'Angular Upload Files';

Run the App

First we need to create uploads folder with the path resources/static/assets (on server side). Run Node.js Server with command: node server.js.

Because we configure CORS for origin: http://localhost:8081, so you need to run Angular 8 Client with command:
ng serve --port 8081

Open Browser with url http://localhost:8081/ and check the result.

Further Reading

Angular 8 + Node.js Express + MySQL: CRUD example
Angular 8 + Node.js Express + PostgreSQL: CRUD example
Angular 8 + Node.js Express + MongoDB: CRUD example
Angular 8+ Node.js Express: JWT Authentication & Authorization example
Server side Pagination with Node.js and Angular 11/10/8


Today we’re learned how to build File Upload example using Angular 8 and Node.js Express. We also provide the ability to show list of files, upload progress using Bootstrap, and to download file from the server.

You can find Step by Step to implement the Node.js Server at:
Node.js Express File Upload Rest API example using Multer

If you want to upload multiple files at once like this:


You can find the instruction here:
Angular 8 Multiple Files upload example

Or multiple images here:
Angular 8 upload Multiple Images example

You will want to know how to run both projects in one place:
How to Integrate Angular 8 with Node.js Restful Services

Source Code

The source code for the Angular 8 Client is uploaded to Github.

Leave a Reply

Your email address will not be published. Required fields are marked *