티스토리 뷰
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
public class S3Util {
Regions clientRegion = Regions.AP_NORTHEAST_2;
final String bucketName = "버킷네임";
final String accesskey = "액세스키";
final String secretkey = "비밀키";
public String getBucketName() {
return bucketName;
}
public String getAccessKey() {
return accesskey;
}
public String getSecretKey() {
return secretkey;
}
private AmazonS3 conn;
public S3Util() {
AWSCredentials credentials = new BasicAWSCredentials(this.getAccessKey(), this.getSecretKey());
this.conn = AmazonS3ClientBuilder.standard()
.withRegion(clientRegion)
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.build();
enableVersioning();
}
/**
* Enable versioning on the bucket.
*/
public void enableVersioning() {
BucketVersioningConfiguration configuration =
new BucketVersioningConfiguration().withStatus("Enabled");
SetBucketVersioningConfigurationRequest setBucketVersioningConfigurationRequest =
new SetBucketVersioningConfigurationRequest(bucketName,configuration);
conn.setBucketVersioningConfiguration(setBucketVersioningConfigurationRequest);
// 2. Get bucket versioning configuration information.
BucketVersioningConfiguration conf = conn.getBucketVersioningConfiguration(bucketName);
System.out.println("bucket versioning configuration status: " + conf.getStatus());
}
/**
* Upload a file as a new object with ContentType and title specified.
* @param fileObjKeyName
* @param fileName
*/
public void uploadFile(String fileObjKeyName , String fileName) {
PutObjectRequest request = new PutObjectRequest(bucketName, fileObjKeyName, new File(fileName));
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("plain/text");
metadata.addUserMetadata("x-amz-meta-title", "블라블라");
request.setMetadata(metadata);
conn.putObject(request);
}
}
|
메인
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
/**
* AWS S3 파일업로드
* @param fileName
*/
private void sendAWSFile(String fileName ) {
final String S3FOLDER = "data/";
if(StringUtils.isBlank(fileName)) {
return;
}
String destFileName = fileName;
if(fileName.indexOf('_') >= 0) {
destFileName = fileName.substring(fileName.indexOf('_')+1 , fileName.length());
}
S3Util s3 = new S3Util();
s3.uploadFile(S3FOLDER+destFileName+".csv", fileName+".csv");
}
|
반응형
'DEV > JAVA' 카테고리의 다른 글
| Spring AI, 자바 개발자를 위한 AI 활용법: 장점과 단점 심층 분석 (0) | 2026.01.04 |
|---|---|
| 자바, 버전별 주요 특징 및 변화 (3) | 2025.07.15 |
| spring boot + jasypt (0) | 2017.09.15 |
| StringUtils.isEmtpty() vs StringUtils.isBlank() (0) | 2016.03.18 |
| POI 로 엑셀파일 읽기(xls , xlsx) (0) | 2016.03.14 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 직구
- springai
- 웹스크래핑
- 생산성향상
- Rag
- spring프레임워크
- selenium
- 프롬프트엔지니어링
- 데이터베이스
- 펄
- 크로미움
- Oracle
- 개발생산성
- 업무자동화
- n8n
- Java
- 배민
- AI솔루션
- 오픈소스DB
- 도커
- 비즈니스성장
- 배민문방구
- SEO최적화
- springboot
- llm최적화
- 코드생성AI
- 웹개발
- 자바AI개발
- 해외
- restapi
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함