Java용 AWS SDK
"sample-object";
String filePath = "/tmp/sample.txt";
try {
s3.putObject(bucketName, objectName, new File(filePath));
System.out.format("Object %s has been created.\n", objectName);
} catch (AmazonS3Exception e) {
e.printStackTrace();
} catch(SdkClientException e) {
e.printStackTrace();
}
파일 목록 조회
파일 목록 조회의 예제는 다음과 같습니다.
final String endPoint = "https://kr.object.gov-ncloudstorage.com";
final String regionName = "gov-standard";
final String accessKey = "ACCESS_KEY";
final String secretKey = "SECRET_KEY";
// S3 client
final AmazonS3 s3 = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, regionName))
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
.build();
String bucketName = "sample-bucket";
// list all in the bucket
try {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
.withBucketName(bucketName)
.withMaxKeys(300);
ObjectListing objectListing = s3.listObjects(listObjectsRequest);
System.out.println("Object List:");
while (true) {
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
System.out.println(" name=" + objectSummary.getKey() + ", size=" + objectSummary.getSize() + ", owner=" + objectSummary