-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs : 최초 실행시 Sample Data 넣는 방법 추가 * style : 오탈자수정 * feat : Naver Object Storage Properties기능 구현 - Notion 설정 방법 추가 - ObjectStorage 설정값 추가 - NaverObjectStorageProperties Bean 생성 구현 * chore : Server Port 분리 - Local, Dev모두 8080인것 확인하여 변경 - local : 8080, dev : 80번포트 변경 * chore : 파일관련 의존성 및 설정 추가 - bucket-name 추가 - 파일 관리시 Bucket-Name필요하나 누락으로 인한 추가 - Properties 속성 추가 - Dependency 의존성 추가 - AWS-SDK추가 : ObjectStorage 파일 Management - Apache Common IO 추가 : 유틸리티 사용을 하고자 추가 * feat : File사용 관련 Common Exception 생성 - Upload Exception - Delete Exception * feat : 파일 업로드 기능 구현완료 - FileDeleteException 불필요 의존성 제거 - application.yml 불필요 속성 삭제 - FileIO작업관련 Exception - Enum추가 - Exception 추N - File Upload관련 예제 추가 - NaverController, upload-form.html - ObjectStorage기능 구현 - NaverObjectStorageConfig Bean 구현 - NaverObjectStorageUsageType Enum 구현 - Type을 통한 분류 - NaverObjectStorageUtil 공통 파일업로드 기능 구현 * refactor : 오탈자 및 누락 속성 추가
- Loading branch information
1 parent
bc3dbde
commit 98d5c64
Showing
16 changed files
with
384 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ | |
public class HomeController { | ||
@GetMapping("/") | ||
public String index() { | ||
return "/index"; | ||
return "index"; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
Api/src/main/java/picasso/server/api/naver_test/NaverController.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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package picasso.server.api.naver_test; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.multipart.MultipartFile; | ||
import picasso.server.common.properties.NaverObjectStorageProperties; | ||
import picasso.server.common.util.NaverObjectStorageUsageType; | ||
import picasso.server.common.util.NaverObjectStorageUtil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
/* | ||
TODO : 기능개발 완료이후 삭제해야 할 파일 | ||
*/ | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Controller | ||
@RequestMapping("/naver") | ||
public class NaverController { | ||
private final NaverObjectStorageProperties naverObjectStorageProperties; | ||
private final NaverObjectStorageUtil naverObjectStorageUtil; | ||
|
||
@GetMapping("/properties-test") | ||
@ResponseBody | ||
public ResponseEntity<String> naverTest() { | ||
return ResponseEntity.ok( | ||
naverObjectStorageProperties.getEndPoint() + " " + | ||
naverObjectStorageProperties.getRegionName() | ||
); | ||
} | ||
|
||
@GetMapping("/file-upload-test-form") | ||
public String uploadTest() { | ||
return "test/upload-form"; | ||
} | ||
|
||
@PostMapping("/file-upload-test") | ||
@ResponseBody | ||
public ResponseEntity fileUploadTest( | ||
@RequestPart(value = "profile", required = false) MultipartFile profile, | ||
@RequestPart(value = "paint", required = false) MultipartFile paint | ||
) { | ||
List<String> filePath = new ArrayList<>(); | ||
if (!profile.isEmpty()) | ||
filePath.add( | ||
naverObjectStorageUtil.storageFileUpload( | ||
NaverObjectStorageUsageType.PROFILE, profile | ||
) | ||
); | ||
if (!paint.isEmpty()) | ||
filePath.add( | ||
naverObjectStorageUtil.storageFileUpload( | ||
NaverObjectStorageUsageType.PAINT, paint | ||
) | ||
); | ||
if (filePath.isEmpty()) | ||
filePath.add("업로드한 파일이 없음"); | ||
|
||
return ResponseEntity.ok(filePath); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html | ||
lang="ko" | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:th="http://www.thymeleaf.org" | ||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" | ||
> | ||
<!-- TODO : 기능개발 완료이후 삭제해야 할 파일 --> | ||
<head th:replace="~{fragment/config :: configFragment}"></head> | ||
<body> | ||
<h1>Upload Test Page</h1> | ||
<form action='/naver/file-upload-test' method='post' enctype='multipart/form-data'> | ||
업로드 대상 파일 (프로필) : <input type='file' name="profile" /><br> | ||
업로드 대상 파일 (미술품게시판) : <input type="file" name="paint" /><br> | ||
<button>등록</button> | ||
</form> | ||
</body> | ||
<script> | ||
</script> | ||
</html> |
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
56 changes: 56 additions & 0 deletions
56
Common/src/main/java/picasso/server/common/config/NaverObjectStorageConfig.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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package picasso.server.common.config; | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.client.builder.AwsClientBuilder; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import picasso.server.common.properties.NaverObjectStorageProperties; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Configuration | ||
public class NaverObjectStorageConfig { | ||
private final NaverObjectStorageProperties naverObjectStorageProperties; | ||
|
||
@Bean | ||
public AmazonS3 storageObject() { | ||
log.info("Create NaverObjectStorageConfig Bean"); | ||
return AmazonS3ClientBuilder.standard() | ||
.withEndpointConfiguration(this.getEndpointConfig()) | ||
.withCredentials(this.getCredentialsProvier()) | ||
.build(); | ||
} | ||
|
||
private AwsClientBuilder.EndpointConfiguration getEndpointConfig() { | ||
log.info( | ||
"Create EndPoint Object >>> EndPoint : {}, RegionName : {}", | ||
this.naverObjectStorageProperties.getEndPoint(), | ||
this.naverObjectStorageProperties.getRegionName() | ||
); | ||
|
||
return new AwsClientBuilder.EndpointConfiguration( | ||
this.naverObjectStorageProperties.getEndPoint(), | ||
this.naverObjectStorageProperties.getRegionName() | ||
); | ||
} | ||
|
||
private AWSStaticCredentialsProvider getCredentialsProvier() { | ||
log.info( | ||
"Create CredentialsProvider >>> AccessKey : {}, SecretKey : {}", | ||
this.naverObjectStorageProperties.getAccessKey(), | ||
this.naverObjectStorageProperties.getSecretKey() | ||
); | ||
|
||
return new AWSStaticCredentialsProvider( | ||
new BasicAWSCredentials( | ||
naverObjectStorageProperties.getAccessKey(), | ||
naverObjectStorageProperties.getSecretKey() | ||
) | ||
); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Common/src/main/java/picasso/server/common/exception/FileDeleteException.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package picasso.server.common.exception; | ||
|
||
import static picasso.server.common.exception.GlobalException.FILE_DELETE_ERROR; | ||
|
||
public class FileDeleteException extends BaseException { | ||
|
||
public static final BaseException EXCEPTION = new FileDeleteException(); | ||
|
||
private FileDeleteException() { | ||
super(FILE_DELETE_ERROR); | ||
} | ||
|
||
} | ||
|
14 changes: 14 additions & 0 deletions
14
Common/src/main/java/picasso/server/common/exception/FileIOException.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package picasso.server.common.exception; | ||
|
||
import static picasso.server.common.exception.GlobalException.FILE_IO_ERROR; | ||
|
||
public class FileIOException extends BaseException { | ||
|
||
public static final BaseException EXCEPTION = new FileIOException(); | ||
|
||
private FileIOException() { | ||
super(FILE_IO_ERROR); | ||
} | ||
|
||
} | ||
|
14 changes: 14 additions & 0 deletions
14
Common/src/main/java/picasso/server/common/exception/FileUploadException.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package picasso.server.common.exception; | ||
|
||
import static picasso.server.common.exception.GlobalException.FILE_UPLOAD_ERROR; | ||
|
||
public class FileUploadException extends BaseException { | ||
|
||
public static final BaseException EXCEPTION = new FileUploadException(); | ||
|
||
private FileUploadException() { | ||
super(FILE_UPLOAD_ERROR); | ||
} | ||
|
||
} | ||
|
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
19 changes: 19 additions & 0 deletions
19
Common/src/main/java/picasso/server/common/properties/NaverObjectStorageProperties.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package picasso.server.common.properties; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@Getter | ||
@ToString | ||
@AllArgsConstructor | ||
@ConfigurationProperties(prefix = "naver.storage") | ||
public class NaverObjectStorageProperties { | ||
|
||
private String endPoint; | ||
private String regionName; | ||
private String accessKey; | ||
private String secretKey; | ||
private String bucketName; | ||
} |
14 changes: 14 additions & 0 deletions
14
Common/src/main/java/picasso/server/common/util/NaverObjectStorageUsageType.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package picasso.server.common.util; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum NaverObjectStorageUsageType { | ||
PROFILE("profile") | ||
, PAINT("paint"); | ||
|
||
|
||
private String path; | ||
} |
Oops, something went wrong.