fixed image locale storage on minio

This commit is contained in:
SlimusMinus
2026-07-10 01:27:30 +03:00
parent 712a5f1e2b
commit f371a442d0
12 changed files with 415 additions and 90 deletions

View File

@@ -1,21 +0,0 @@
package com.krylov.refound.controller;
import com.krylov.refound.service.FileStorageService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
@RequestMapping("/api/v1/files")
@RequiredArgsConstructor
public class FileController {
private final FileStorageService storageService;
@PostMapping
public String upload(@RequestParam("file") MultipartFile file) {
return storageService.save(file);
}
}

View File

@@ -0,0 +1,45 @@
package com.krylov.refound.controller;
import com.krylov.refound.service.FileStorageService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.UriUtils;
import java.nio.charset.StandardCharsets;
@RestController
@RequestMapping("/api/v1/files")
@RequiredArgsConstructor
public class FileStorageController {
private final FileStorageService fileStorageService;
@PostMapping
public ResponseEntity<String> uploadFile(@RequestParam("file") MultipartFile file) {
String objectName = fileStorageService.uploadFile(file);
return ResponseEntity.ok(objectName); // фронт сохранит objectName как ключ картинки
}
@GetMapping("/{objectName}")
public ResponseEntity<byte[]> downloadFile(@PathVariable String objectName) {
FileStorageService.DownloadedFile downloadedFile = fileStorageService.downloadFile(objectName);
String encodedFilename = UriUtils.encode(downloadedFile.originalFilename(), StandardCharsets.UTF_8);
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + encodedFilename);
return ResponseEntity.ok()
.headers(headers)
.contentType(MediaType.parseMediaType(downloadedFile.contentType()))
.body(downloadedFile.content());
}
@DeleteMapping("/{objectName}")
public ResponseEntity<Void> deleteFile(@PathVariable String objectName) {
fileStorageService.deleteFile(objectName);
return ResponseEntity.noContent().build();
}
}