Search in sources :

Example 96 with S3Client

use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.

the class GetBucketPolicy method getPolicy.

// snippet-start:[s3.java2.get_bucket_policy.main]
public static String getPolicy(S3Client s3, String bucketName) {
    String policyText = "";
    System.out.format("Getting policy for bucket: \"%s\"\n\n", bucketName);
    GetBucketPolicyRequest policyReq = GetBucketPolicyRequest.builder().bucket(bucketName).build();
    try {
        GetBucketPolicyResponse policyRes = s3.getBucketPolicy(policyReq);
        policyText = policyRes.policy();
        return policyText;
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
Also used : S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) GetBucketPolicyRequest(software.amazon.awssdk.services.s3.model.GetBucketPolicyRequest) GetBucketPolicyResponse(software.amazon.awssdk.services.s3.model.GetBucketPolicyResponse)

Example 97 with S3Client

use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.

the class GetObjectData method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <bucketName> <keyName> <path>\n\n" + "Where:\n" + "    bucketName - the Amazon S3 bucket name. \n\n" + "    keyName - the key name. \n\n" + "    path - the path where the file is written to. \n\n";
    if (args.length != 3) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucketName = args[0];
    String keyName = args[1];
    String path = args[2];
    Region region = Region.US_EAST_1;
    S3Client s3 = S3Client.builder().region(region).build();
    getObjectBytes(s3, bucketName, keyName, path);
    s3.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) S3Client(software.amazon.awssdk.services.s3.S3Client)

Example 98 with S3Client

use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.

the class GetObjectTags method listTags.

// snippet-start:[s3.java2.getobjecttags.main]
public static void listTags(S3Client s3, String bucketName, String keyName) {
    try {
        GetObjectTaggingRequest getTaggingRequest = GetObjectTaggingRequest.builder().key(keyName).bucket(bucketName).build();
        GetObjectTaggingResponse tags = s3.getObjectTagging(getTaggingRequest);
        List<Tag> tagSet = tags.tagSet();
        // Write out the tags
        Iterator<Tag> tagIterator = tagSet.iterator();
        while (tagIterator.hasNext()) {
            Tag tag = (Tag) tagIterator.next();
            System.out.println(tag.key());
            System.out.println(tag.value());
        }
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : GetObjectTaggingRequest(software.amazon.awssdk.services.s3.model.GetObjectTaggingRequest) GetObjectTaggingResponse(software.amazon.awssdk.services.s3.model.GetObjectTaggingResponse) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) Tag(software.amazon.awssdk.services.s3.model.Tag)

Example 99 with S3Client

use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.

the class ListMultipartUploads method listUploads.

// snippet-start:[s3.java2.list_multi_uploads.main]
public static void listUploads(S3Client s3, String bucketName) {
    try {
        ListMultipartUploadsRequest listMultipartUploadsRequest = ListMultipartUploadsRequest.builder().bucket(bucketName).build();
        ListMultipartUploadsResponse response = s3.listMultipartUploads(listMultipartUploadsRequest);
        List<MultipartUpload> uploads = response.uploads();
        for (MultipartUpload upload : uploads) {
            System.out.println("Upload in progress: Key = \"" + upload.key() + "\", id = " + upload.uploadId());
        }
    } catch (S3Exception e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : ListMultipartUploadsResponse(software.amazon.awssdk.services.s3.model.ListMultipartUploadsResponse) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) MultipartUpload(software.amazon.awssdk.services.s3.model.MultipartUpload) ListMultipartUploadsRequest(software.amazon.awssdk.services.s3.model.ListMultipartUploadsRequest)

Example 100 with S3Client

use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.

the class ManagingObjectTags method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "  <bucketName> <objectKey> <objectPath> \n\n" + "Where:\n" + "  bucketName - the Amazon S3 bucket.\n" + "  objectKey - the object that a tag is applied (for example, book.pdf).\n" + "  objectPath - the path where the file is located (for example, C:/AWS/book2.pdf). \n\n";
    if (args.length != 3) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucketName = args[0];
    String objectKey = args[1];
    String objectPath = args[2];
    System.out.println("Putting object " + objectKey + " into bucket " + bucketName);
    System.out.println("  in bucket: " + bucketName);
    Region region = Region.US_EAST_1;
    S3Client s3 = S3Client.builder().region(region).build();
    putS3ObjectTags(s3, bucketName, objectKey, objectPath);
    updateObjectTags(s3, bucketName, objectKey);
    s3.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) S3Client(software.amazon.awssdk.services.s3.S3Client)

Aggregations

S3Client (software.amazon.awssdk.services.s3.S3Client)63 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)53 Region (software.amazon.awssdk.regions.Region)43 ArrayList (java.util.ArrayList)15 GetObjectRequest (software.amazon.awssdk.services.s3.model.GetObjectRequest)12 GetObjectResponse (software.amazon.awssdk.services.s3.model.GetObjectResponse)12 S3Object (software.amazon.awssdk.services.s3.model.S3Object)11 PutObjectRequest (software.amazon.awssdk.services.s3.model.PutObjectRequest)10 List (java.util.List)7 IOException (java.io.IOException)6 RequestBody (software.amazon.awssdk.core.sync.RequestBody)6 CreateBucketRequest (software.amazon.awssdk.services.s3.model.CreateBucketRequest)6 S3Waiter (software.amazon.awssdk.services.s3.waiters.S3Waiter)6 InputStream (java.io.InputStream)5 Test (org.junit.Test)5 ListObjectsRequest (software.amazon.awssdk.services.s3.model.ListObjectsRequest)5 ListObjectsResponse (software.amazon.awssdk.services.s3.model.ListObjectsResponse)5 SupplierEx (com.hazelcast.function.SupplierEx)3 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3