Angular 6 Client – Upload Files/Download Files to MySQL with SpringBoot RestAPIs example

In the tutorial, we show how to upload/download files from Angular 6 Client to MySQL with SpringBoot RestAPIs.

Related posts:
Angular 6 – Upload/Get MultipartFile to/from Spring Boot Server
How to upload MultipartFile with Spring Boot


  • Angular 6
  • Java 1.8
  • Spring Boot 2.0.3.RELEASE
  • Maven 3.3.9
  • Spring Tool Suite 3.9.0.RELEASE
  • MySQL


SpringBoot Server

We create a SpringBoot project as below:


Using @Lob annotation and Spring JPA to save file’s data to MySQL.

-> MySQL records:


Angular 6 Client

Project structure ->


  • upload-file.service provides methods: push File to Storage and get Files.
  • list-upload.component gets and displays list of Files.
  • form-upload.component helps upload File.
  • details-upload.component is detail for each item in list of Files.



SpringBoot Server
Create SpringBoot project

We create a SpringBoot project with below dependencies:

  • spring-boot-starter-thymeleaf
  • spring-boot-starter-web
  • spring-boot-starter-data-jpa
  • mysql

-> Details:

Data Model

– Create a View with @JsonView in ‘’ file:

– Create ‘’ file:

JPA Repository

Implement JPA repository in ‘’ file:

– Configure @EnableTransactionManagement in main class ‘’:

Upload/Download RestAPIs

– Implement upload-file RestAPI in ‘’ file:

– Implement download/retrieve files RestAPIs in ‘’ file:

– Configure cross-origin for Angular-Client which running at port 4200 ->

@CrossOrigin(origins = "http://localhost:4200")

MySQL Connection

– Add setting in ‘’ file:

Angular 6 Client
Generate Service & Components

Run commands below:
ng g s upload/UploadFile
ng g c upload/FormUpload
ng g c upload/ListUpload
ng g c upload/DetailsUpload

On each Component selector, delete app- prefix, then change tslint.json rules – "component-selector" to false.

App Module

app.module.ts ->

Upload File Service

upload/upload-file.service.ts ->

Component for getting List of Files

upload/list-upload.component.ts ->

upload/list-upload.component.html ->

upload/details-upload.component.ts ->

upload/details-upload.component.html ->

Component for uploading File

upload/form-upload.component.ts ->

upload/form-upload.component.html ->

App Component

app.component.ts ->

app.component.html ->

Run & Check Results

Run SpringBoot Server (using mvn spring-boot:run) and Angular 6 Client App (using ng serve)
Then open Browser with url http://localhost:4200/.

-> Upload files and show list of Files:


-> MySQL records:


-> Click to the links to download files:



By grokonez | July 5, 2018.

Last updated on February 6, 2020.

Related Posts

6 thoughts on “Angular 6 Client – Upload Files/Download Files to MySQL with SpringBoot RestAPIs example”

  1. You are amazing…

    But I have one question, what if I just want post data object from formless form? Do I still need to use HttpEvent Observable? Can post post method and subscribe to it, from a component?

Got Something To Say:

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