Category: github

In this article we will look at how to upload file from an HTML page and copy it to the file system on the server. The below HTML code and its corresponding Javascript code creates the HTML form and binds the form with the API created in your Spring Boot application: enctype="multipart/form-data" is an important attribute which should be present in the that deals with uploading files.

There will be two components in the server side: Below is the code for the API to receive the uploaded files: It is important to note that the value passed to the annotation @RequestParam should match the value of the name attribute of the HTML element.

By default the uploaded file is wrapped in StandardMultipartFile which is one of the implementations of MultipartFile. We make use of the method transferTo to copy the uploaded file to our desired destination on the file system.

Related Articles