I have two microservices:
- One for user authentication (authentication microservice).
- One for handling video file storage (videoStore microService).
Process :
- ("/create") belongs to authentication microservice
- ("/create") is accessible only with well formed token (JWT).
- ("/create") receives multipartFile
- ("/create") sends multipartFile to storage service
- ("/uploadfile") belongs to file storage microservice
- ("/uploadfile") performs the storage of the file into linux filesystem
@PostMapping(value ="/create")
ResponseEntity<Response> createVideo(@RequestParam("file") MultipartFile multipartFile)
{
videoRestClientService.upload(multipartFile);
return new ResponseEntity<Response>(new Response("video has been stored"), HttpStatus.OK);
}
public Response upload(MultipartFile multipartFile){
RestClient restClient = RestClient.create("http://localhost:8095");
Response response = restClient.post()
.uri("/uploadfile")
.contentType(...)
.body(multipartFile)
.retrieve()
.body(Response.class);
}
-> In videoStore microService
@PostMapping("/uploadfile")
public ResponseEntity<Response> uploadFile(@RequestParam("file") MultipartFile multipartFile) {
Response response = fileSystemStorage.storeFile(multipartFile);
return new ResponseEntity<Response>(response, HttpStatus.OK);
}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.1.2</version>
</dependency>
Question :
- Is it possible to use restClient to post multipartFile ?
Remark :
- I don't have any getway implemented (don't have the skills yet).
- The authentication service is doing the getway job (to bad for clean archicture).