앱)AWS S3 Util java spring 예제 샘플
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.0</version>
</dependency>
@Configuration
public class AWSS3Util{
@Value("${s3.accessKey}")
private String accessKey;
@Value("${s3.secretKey}")
private String secretKey;
@Value("${s3.region}")
private String region;
@Bean
public AmazonS3 amazonS3Client(){
String tmpAccessKey = "";
String tmpSecretKey="";
if("Local".equals(System.getProperty("server.type"))){
tmpAccessKey = accessKey;
tmpSecretKey = secretKey;
}else{
tmpAccessKey = AESCipherUtil.decrypt(accessKey);
tmpSecretKey = AESCipherUtil.decrypt(secretKey);
}
AWSCredentials credentials = new BasicAWSCredentials(tmpAccessKey, tmpSecretKey);
AmazonS3 s3Client = null;
if("Local".equals(System.getProperty("server.type"))){
ClientConfiguration clientCfg = new ClientConfiguration();
clientCfg.setProtocol(Protocol.HTTP);
clientCfg.setProxyHost("");
clientCfg.setProxyPort();
s3Client = new AmazonS3Client(credentials, clientCfg);
}else{
s3Client = new AmazonS3Client(credentials);
}
Region regionCode = null;
switch (region) {
case="EU_WEST_1":
regionCode = Region.getRegion(Regions.EU_WEST_1);
break;
case="AP_NORTHEAST_1":
regionCode = Region.getRegion(Regions.AP_NORTHEST_1);
break;
}
s3Client.setRegion(regionCode);
return s3Client;
}
}
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.0</version>
</dependency>
@Configuration
public class AWSS3Util{
@Value("${s3.accessKey}")
private String accessKey;
@Value("${s3.secretKey}")
private String secretKey;
@Value("${s3.region}")
private String region;
@Bean
public AmazonS3 amazonS3Client(){
String tmpAccessKey = "";
String tmpSecretKey="";
if("Local".equals(System.getProperty("server.type"))){
tmpAccessKey = accessKey;
tmpSecretKey = secretKey;
}else{
tmpAccessKey = AESCipherUtil.decrypt(accessKey);
tmpSecretKey = AESCipherUtil.decrypt(secretKey);
}
AWSCredentials credentials = new BasicAWSCredentials(tmpAccessKey, tmpSecretKey);
AmazonS3 s3Client = null;
if("Local".equals(System.getProperty("server.type"))){
ClientConfiguration clientCfg = new ClientConfiguration();
clientCfg.setProtocol(Protocol.HTTP);
clientCfg.setProxyHost("");
clientCfg.setProxyPort();
s3Client = new AmazonS3Client(credentials, clientCfg);
}else{
s3Client = new AmazonS3Client(credentials);
}
Region regionCode = null;
switch (region) {
case="EU_WEST_1":
regionCode = Region.getRegion(Regions.EU_WEST_1);
break;
case="AP_NORTHEAST_1":
regionCode = Region.getRegion(Regions.AP_NORTHEST_1);
break;
}
s3Client.setRegion(regionCode);
return s3Client;
}
}
'백엔드개발 > 자바스프링' 카테고리의 다른 글
앱)java springframework select box jstl form sample 예제 (0) | 2018.06.11 |
---|---|
앱)logback 한줄 로그 나오게 하는 방법 (0) | 2018.06.08 |
앱)자바 batch pid 파일 만들기 (0) | 2018.04.27 |
앱)jar 파일 실행하는 법 정리 (0) | 2018.04.13 |
스프링 프레임워크 메인 프로젝트 Spring framework project (0) | 2018.04.05 |