Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: use cache in minio image endpoint #821

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/main/java/me/universi/image/controller/ImageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public Response upload_of_image(@RequestParam("imagem") MultipartFile image) {

// get image from minIO
@GetMapping(value = "/img/minio/{imageId}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
@Cacheable("img")
public ResponseEntity<byte[]> getImageFromMinio(@PathVariable("imageId") String imageId) {
try {
//Recupera a imagem do MinIO
Expand All @@ -70,9 +72,12 @@ public ResponseEntity<byte[]> getImageFromMinio(@PathVariable("imageId") String
stream.close();

//Retorna os bytes da imagem com um status HTTP 200 OK
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(imageBytes);
return ResponseEntity
.ok()
.contentLength(imageBytes.length)
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.cacheControl(CacheControl.maxAge(365, TimeUnit.DAYS))
.body(imageBytes);
} catch (Exception e) {
//Se ocorrer um erro ao recuperar a imagem, retorna um status HTTP 404 Not Found
return ResponseEntity.notFound().build();
Expand Down
Loading