-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c434f1b
commit e8b8af2
Showing
7 changed files
with
67 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 22 additions & 20 deletions
42
src/main/java/com/groomiz/billage/classroom/service/S3Service.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,34 @@ | ||
package com.groomiz.billage.classroom.service; | ||
|
||
import java.io.IOException; | ||
import java.net.URLDecoder; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
import java.io.IOException; | ||
|
||
import java.net.URLDecoder; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
|
||
@Service | ||
public class S3Service { | ||
private final AmazonS3 amazonS3; | ||
|
||
@Value("${cloud.aws.s3.bucket-name}") | ||
private String bucketName; | ||
|
||
public String uploadFile(MultipartFile imageFile, String s3FileName) throws IOException { | ||
// 메타데이터 생성 | ||
ObjectMetadata objMeta = new ObjectMetadata(); | ||
objMeta.setContentLength(imageFile.getInputStream().available()); | ||
// S3에 객체 등록 | ||
amazonS3.putObject(bucketName, s3FileName, imageFile.getInputStream(), objMeta); | ||
// 등록된 객체의 url 반환 | ||
return URLDecoder.decode(amazonS3.getUrl(bucketName, s3FileName).toString(), "utf-8"); | ||
} | ||
private final AmazonS3 amazonS3; | ||
|
||
@Value("${cloud.aws.s3.bucket-name}") | ||
private String bucketName; | ||
|
||
public String uploadFile(MultipartFile imageFile, String s3FileName) throws IOException { | ||
// 메타데이터 생성 | ||
ObjectMetadata objMeta = new ObjectMetadata(); | ||
objMeta.setContentLength(imageFile.getInputStream().available()); | ||
// S3에 객체 등록 | ||
amazonS3.putObject(bucketName, s3FileName, imageFile.getInputStream(), objMeta); | ||
// 등록된 객체의 url 반환 | ||
return URLDecoder.decode(amazonS3.getUrl(bucketName, s3FileName).toString(), "utf-8"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters