WIP for images

This commit is contained in:
2025-04-24 07:34:53 +02:00
parent a3d3a01d3a
commit 6b5dded7f8
6 changed files with 119 additions and 35 deletions

View File

@@ -113,8 +113,8 @@ public class NoticeService {
}
}
public String saveImage(Long noticeId, MultipartFile file) throws IOException {
String uploadDir = "src/main/resources/static/images/notices/" + noticeId;
public String saveImage(String uploadFolder, Long noticeId, MultipartFile file) throws IOException {
String uploadDir = uploadFolder + noticeId;
Path uploadPath = Paths.get(uploadDir);
if (!Files.exists(uploadPath)) {
@@ -141,12 +141,11 @@ public class NoticeService {
.orElse(0);
fileName = baseName + (maxNumber + 1) + extension;
} else {
throw new IOException("Nie można znaleźć nazwy pliku");
}
//koniec szukania nazwy pliku
if(fileName == null) {
throw new IOException("Nie można znaleźć nazwy pliku");
}
Path filePath = uploadPath.resolve(fileName);
Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);