First, a way to achieve this using Spring MVC should look like this:
@RestController
@RequestMapping("/files")
public class FileController {
@GetMapping("/{fileName}")
public Resource getFile(@PathVariable String fileName) {
Resource resource = new FileSystemResource(fileName);
return resource;
}
}
Also, not so, if you simply load these resources without additional logic, you can use Spring MVC static resource support . Using Spring Boot spring.resources.static-locationscan help you set up your location.
, Spring WebFlux, spring.resources.static-locations .
WebFlux . -, Mono<Resource> Resource, :
@RestController
@RequestMapping("/files")
public class FileController {
@GetMapping("/{fileName}")
public Mono<Resource> getFile(@PathVariable String fileName) {
return fileRepository.findByName(fileName)
.map(name -> new FileSystemResource(name));
}
}
, WebFlux, Resource , zero-copy, .