Skip to content

Commit

Permalink
투데이 시큐리티 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
duhwan05 committed Aug 22, 2024
1 parent b71e970 commit ac28619
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/example/healthylife/service/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

1 comment on commit ac28619

@seung-jun2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋아용

Please sign in to comment.