diff --git a/src/main/java/com/example/healthylife/config/security/SecurityConfig.java b/src/main/java/com/example/healthylife/config/security/SecurityConfig.java index bb90415..2c0a5d5 100644 --- a/src/main/java/com/example/healthylife/config/security/SecurityConfig.java +++ b/src/main/java/com/example/healthylife/config/security/SecurityConfig.java @@ -33,6 +33,7 @@ protected void configure(HttpSecurity http) throws Exception { .authorizeRequests() .antMatchers("/community/register", "/community/update", "/community/delete/**","/community/recommend/**","/community/myCommunityContents").authenticated() .antMatchers("/user/one","/user/delete","/user/update").authenticated() + .antMatchers("/today/create","/today/myTodayContents","/today/update/**","/today/delete/**","/today/todayDetail/**").authenticated() .anyRequest().permitAll() .and() .addFilterBefore(new JwtAuthenticationFilter(jwtUtil), UsernamePasswordAuthenticationFilter.class); diff --git a/src/main/java/com/example/healthylife/controller/TodayController.java b/src/main/java/com/example/healthylife/controller/TodayController.java index 93c7fae..0a23059 100644 --- a/src/main/java/com/example/healthylife/controller/TodayController.java +++ b/src/main/java/com/example/healthylife/controller/TodayController.java @@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Optional; diff --git a/src/main/java/com/example/healthylife/service/S3Service.java b/src/main/java/com/example/healthylife/service/S3Service.java index d81431e..ef002d0 100644 --- a/src/main/java/com/example/healthylife/service/S3Service.java +++ b/src/main/java/com/example/healthylife/service/S3Service.java @@ -25,12 +25,13 @@ public S3Service(S3Client s3Client) { // 파일 업로드 public String uploadFileToS3(MultipartFile file) { - String fileName = file.getOriginalFilename(); + String fileName = System.currentTimeMillis() + "_" + file.getOriginalFilename(); try { PutObjectRequest putObjectRequest = PutObjectRequest.builder() .bucket(bucketName) .key(fileName) + .contentType(file.getContentType()) // Content-Type 설정 .build(); PutObjectResponse putObjectResponse = s3Client.putObject(putObjectRequest, @@ -40,9 +41,10 @@ public String uploadFileToS3(MultipartFile file) { return "https://" + bucketName + ".s3.amazonaws.com/" + fileName; } catch (IOException e) { - throw new RuntimeException("S3 파일 업로드 실패", e); + throw new RuntimeException("S3 파일 업로드 실패: " + e.getMessage(), e); } } + // 파일 삭제 public void deleteFileFromS3(String fileName) { diff --git a/src/main/java/com/example/healthylife/service/TodayService.java b/src/main/java/com/example/healthylife/service/TodayService.java index a057ed3..91cf76a 100644 --- a/src/main/java/com/example/healthylife/service/TodayService.java +++ b/src/main/java/com/example/healthylife/service/TodayService.java @@ -81,7 +81,6 @@ public TodayEntity updateEntity(Long todayId, String content, MultipartFile file String existingFileName = existingImageUrl.substring(existingImageUrl.lastIndexOf('/') + 1); s3Service.deleteFileFromS3(existingFileName); } - // 새로운 이미지 업로드 String newImageUrl = s3Service.uploadFileToS3(file); existingTodayEntity.setImageurl(newImageUrl);