Skip to content

Commit

Permalink
💡 :: comment delete
Browse files Browse the repository at this point in the history
  • Loading branch information
lgwk42 committed Dec 7, 2024
1 parent adf6fd5 commit b572098
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ private void validateImageFileExtension(String filename) {
}

private String uploadImageToS3(MultipartFile image) throws IOException {
String originalFilename = image.getOriginalFilename(); //원본 파일 명
String originalFilename = image.getOriginalFilename();
assert originalFilename != null : NullPointerException.class;
String extension = originalFilename.substring(originalFilename.lastIndexOf(".")); //확장자 명
String extension = originalFilename.substring(originalFilename.lastIndexOf("."));

String s3FileName = UUID.randomUUID().toString().substring(0, 10) + originalFilename; //변경된 파일 명
String s3FileName = UUID.randomUUID().toString().substring(0, 10) + originalFilename;

InputStream is = image.getInputStream();
byte[] bytes = IOUtils.toByteArray(is);
Expand All @@ -92,7 +92,7 @@ private String uploadImageToS3(MultipartFile image) throws IOException {
PutObjectRequest putObjectRequest =
new PutObjectRequest(bucketName, s3FileName, byteArrayInputStream, metadata)
.withCannedAcl(CannedAccessControlList.PublicRead);
amazonS3.putObject(putObjectRequest); // put image to S3
amazonS3.putObject(putObjectRequest);
}catch (Exception e){
throw new AmazonS3Exception("S3 업로드 에러");
}finally {
Expand All @@ -115,7 +115,7 @@ private String getKeyFromImageAddress(String imageAddress){
try{
URL url = new URL(imageAddress);
String decodingKey = URLDecoder.decode(url.getPath(), "UTF-8");
return decodingKey.substring(1); // 맨 앞의 '/' 제거
return decodingKey.substring(1);
}catch (MalformedURLException | UnsupportedEncodingException e){
throw new AmazonS3Exception("이미지 삭제 에러");
}
Expand Down

0 comments on commit b572098

Please sign in to comment.