I am new to Servlets and Spring Framework. I try to get media files from directory through Rest Service.
For videos/mp4 I couldn't find anything.
For audio I did this: Writing mp3 file to response output stream
For images I did this:
@RequestMapping("/tmp/{uuid}")
@ResponseBody
public ResponseEntity<InputStreamResource> getTmp(@PathVariable("uuid") String uuid)
throws IOException {
Path path = Paths.get("/media/psmaster/HDD/TUC-IPS/" + uuid);
String contentType = Files.probeContentType(path);
FileSystemResource file = new FileSystemResource("/media/psmaster/HDD/TUC-IPS/" + uuid);
return ResponseEntity
.ok()
.contentLength(file.contentLength())
.contentType(
MediaType.parseMediaType(contentType))
.body(new InputStreamResource(file.getInputStream()));
}
Can someone please help to figure out the problem?