Skip to content

Commit

Permalink
Merge pull request #18 from SafeNet-2024/fix/s3-korean-filenames
Browse files Browse the repository at this point in the history
[fix] ν•œκΈ€ 파일λͺ…이 ν¬ν•¨λœ νŒŒμΌμ„ S3μ—μ„œ μ‚­μ œν•  수 μ—†λŠ” 문제 μˆ˜μ •
  • Loading branch information
khee2 authored Jun 4, 2024
2 parents a3e459d + 89265c1 commit df435b8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,27 @@ public S3Controller(S3Service s3Service) {

@PostMapping(path = "/s3/test", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<String> uploadFile(
@RequestPart(value = "receiptImage") MultipartFile receiptImage,
@RequestPart(value = "productImage") MultipartFile productImage
@RequestPart(value = "receiptImage") MultipartFile receiptImage
) throws IOException {
String receipt_fileName = receiptImage.getOriginalFilename();
String product_fileName = productImage.getOriginalFilename();

String receiptUrl = s3Service.upload("receiptImage", receipt_fileName, receiptImage);
String productUrl = s3Service.upload("productImage", product_fileName, productImage);
log.info("receipt_url is : " + receiptUrl);
log.info("product_url is : " + productUrl);
return new ResponseEntity<>("Receipt URL: " + receiptUrl + "\nProduct URL: " + productUrl, HttpStatus.OK);
return new ResponseEntity<>("Receipt URL: " + receiptUrl, HttpStatus.OK);
}

@DeleteMapping(path = "/s3/test")
public ResponseEntity<String> deleteFile(
@RequestParam(value = "fileUrl") String fileUrl
) {
try {
// S3Serviceλ₯Ό μ‚¬μš©ν•˜μ—¬ 파일 μ‚­μ œ
s3Service.delete(fileUrl);
// μ‚­μ œ 성곡 λ©”μ‹œμ§€ λ°˜ν™˜
return ResponseEntity.ok("File deleted successfully");
} catch (Exception e) {
// μ‚­μ œ μ‹€νŒ¨ μ‹œ μ˜ˆμ™Έ 처리
log.error("Failed to delete file: {}", e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to delete file");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -86,6 +88,8 @@ private String generateUniqueFilename(String originalFilename) {
}

private String extractFileKey(String fileUrl) {
return fileUrl.substring(fileUrl.indexOf(bucket) + bucket.length() + 1);
// S3 버킷 URL λΆ€λΆ„ μ œκ±°ν•˜μ—¬ 파일 ν‚€ μΆ”μΆœ
String fileKey = fileUrl.substring(fileUrl.indexOf(bucket) + bucket.length() + 1); // 버킷 이름을 μ œμ™Έν•œ λ‚˜λ¨Έμ§€ 뢀뢄을 파일 ν‚€λ‘œ μΆ”μΆœ
return URLDecoder.decode(fileKey, StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.exceptionHandling(exception -> exception
.authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED))) // 인증 μ‹€νŒ¨μ‹œ HTTP 401 λ°˜ν™˜
.authorizeHttpRequests(auth -> auth
.requestMatchers("/", "/api/auth/**", "/swagger-ui/**", "/v3/api-docs/**").permitAll() // νŠΉμ • κ²½λ‘œμ— λŒ€ν•œ μ ‘κ·Ό ν—ˆμš©
.requestMatchers("/", "/api/auth/**", "/swagger-ui/**", "/v3/api-docs/**", "/s3/test").permitAll() // νŠΉμ • κ²½λ‘œμ— λŒ€ν•œ μ ‘κ·Ό ν—ˆμš©
// .requestMatchers(HttpMethod.GET,"/api/v2/posts/{postId}").permitAll() // GET μš”μ²­ ν—ˆμš©
.anyRequest().authenticated()) // λ‚˜λ¨Έμ§€ μš”μ²­μ€ 인증 ν•„μš”
//.formLogin(form -> form
Expand Down

0 comments on commit df435b8

Please sign in to comment.