Multipart File Upload Client Using Spring REST Template

In this example I am going to show you how to test file upload using Spring Boot Rest Template API. You can always use any REST based testing tools, such as, Postman, Talend, etc. but when you do not have any access to such REST based client tools, for example, your organization has blocked access to such REST client tools.

When you do not have access to such tools or installation for such tools is not allowed in your system then you can use RestTemplate to test the file upload functionality.


Java 19, Spring Boot 3.1.0, Maven 3.8.5

You can go through the tutorial on Multiple Files Upload Using Spring REST API.

Project Setup

You can create a maven based project in your favorite tool or IDE. The following pom.xml file can be used for the project reference.

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns=""




File Upload Client

The file upload client will test the file upload functionality using Spring’s RestTemplate API.

public static void testMultipleFilesUpload() throws IOException {
	LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
			new FileSystemResource(new File("")));
	map.add("multipleFiles", new FileSystemResource(
			new File("recommended pre-requisites.docx")));

	HttpHeaders headers = new HttpHeaders();

	HttpEntity<LinkedMultiValueMap<String, Object>> reqEntity = new HttpEntity<LinkedMultiValueMap<String, Object>>(
			map, headers);

	RestTemplate restTemplate = new RestTemplate();

	ResponseEntity<String> resE ="http://localhost:8080/upload/multiple/files",
			HttpMethod.POST, reqEntity, String.class);


In the above method I have put the multiple files in the multipleFiles key of the map object. You will also have such key for file upload functionality in the server side code.

You need to configure the http header with multipart form data. Then you are going to call the REST API of file upload functionality using RestTemplate object.

Testing Files Upload Functionality

Once you run the client Java class for uploading files, you will see the similar kind of response as shown below:

<200 OK OK,File Name:
File Name: recommended pre-requisites.docx
,[Content-Type:"text/plain;charset=UTF-8", Content-Length:"117", Date:"07:19:31 GMT", Keep-Alive:"timeout=60", Connection:"keep-alive"]>

Hope you got an idea how to test multiple files upload functionality using Rest Template API.

Source Code


Leave a Reply

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