-
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.
Browse files
Browse the repository at this point in the history
Feature/#97
- Loading branch information
Showing
12 changed files
with
209 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.developer.wiki.config; | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.client.builder.AwsClientBuilder; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class S3Config { | ||
|
||
@Value("${cloud.aws.credentials.access-key}") | ||
private String accessKey; | ||
|
||
@Value("${cloud.aws.credentials.secret-key}") | ||
private String secretKey; | ||
|
||
@Value("${cloud.aws.region.static}") | ||
private String region; | ||
|
||
@Value("${cloud.aws.s3.endpoint}") | ||
private String endPoint; | ||
|
||
@Bean | ||
public AmazonS3Client amazonS3Client() { | ||
System.out.println("엔드 포인트!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+endPoint); | ||
BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey,secretKey); | ||
return (AmazonS3Client) AmazonS3ClientBuilder.standard() | ||
.withCredentials(new AWSStaticCredentialsProvider(awsCreds)) | ||
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, region)) | ||
.build(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.developer.wiki.oauth.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ImageDto { | ||
private String imageUrl; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/developer/wiki/oauth/dto/NicknameDto.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 com.developer.wiki.oauth.dto; | ||
|
||
import lombok.*; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.Pattern; | ||
import javax.validation.constraints.Size; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
public class NicknameDto { | ||
@NotBlank(message = "닉네임은 null일 수 없습니다.") | ||
@Pattern(regexp="^(?=.*[a-z0-9가-힣])[a-z0-9가-힣]{2,10}$", message = "닉네임 조건 불일치") | ||
private String userName; | ||
public NicknameDto(String userName){ | ||
this.userName=userName; | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
src/main/java/com/developer/wiki/oauth/util/AwsService.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,59 @@ | ||
package com.developer.wiki.oauth.util; | ||
|
||
|
||
import com.amazonaws.AmazonClientException; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.model.Bucket; | ||
import com.amazonaws.services.s3.model.PutObjectRequest; | ||
import com.amazonaws.services.s3.transfer.TransferManager; | ||
import com.amazonaws.services.s3.transfer.TransferManagerBuilder; | ||
import com.amazonaws.services.s3.transfer.Upload; | ||
import com.developer.wiki.config.S3Config; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
@Service | ||
@RequiredArgsConstructor | ||
public class AwsService { | ||
// @Value("${cloud.aws.defaultUrl}") | ||
private final String defaultUrl="https://kr.object.ncloudstorage.com/devwiki/"; | ||
// | ||
// @Value("${cloud.aws.s3.bucket}") | ||
private final String bucketName="devwiki"; | ||
private final S3Config s3Config; | ||
|
||
|
||
public void S3Test(){ | ||
|
||
|
||
List<Bucket> buckets = s3Config.amazonS3Client().listBuckets(); | ||
System.out.println("Bucket List: "); | ||
for (Bucket bucket : buckets) { | ||
System.out.println(" name=" + bucket.getName() + ", creation_date=" + bucket.getCreationDate() + ", owner=" + bucket.getOwner().getId()); | ||
} | ||
|
||
} | ||
|
||
public String upload(String saveFileName,MultipartFile multipartFile) throws IOException { | ||
File file = new File(System.getProperty("user.dir") + saveFileName); | ||
multipartFile.transferTo(file); | ||
final TransferManager transferManager = TransferManagerBuilder.standard().withS3Client(s3Config.amazonS3Client()).build(); | ||
System.out.println(saveFileName); | ||
final PutObjectRequest request = new PutObjectRequest(bucketName, saveFileName, file); | ||
final Upload upload = transferManager.upload(request); | ||
try { | ||
upload.waitForCompletion(); | ||
return defaultUrl+saveFileName; | ||
} catch (AmazonClientException | InterruptedException amazonClientException) { | ||
amazonClientException.printStackTrace(); | ||
return null; | ||
}finally { | ||
file.delete(); | ||
} | ||
} | ||
} |
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,13 @@ | ||
cloud: | ||
aws: | ||
credentials: | ||
access-key: ENC(cGBvyLuYjKZ6eldcPBUNLOuO08CGMKetB8njxUmcJOM=) | ||
secret-key: ENC(mN3n2krPI0WFexB4NGfwdAuY6TK3GxT3GfvLtGy6AIf18xTnri3PUHO9l+y5jGiQf7qqI0s6B1M=) | ||
stack: | ||
auto: false | ||
region: | ||
static: ap-northeast-2 | ||
s3: | ||
endpoint: https://kr.object.ncloudstorage.com | ||
bucket: devwiki | ||
defaultUrl : https://kr.object.ncloudstorage.com/devwiki |
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