Search in sources :

Example 86 with S3Client

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

the class S3Service method getClient.

// Create the S3Client object.
private S3Client getClient() {
    Region region = Region.US_WEST_2;
    S3Client s3 = S3Client.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
    return s3;
}
Also used : Region(software.amazon.awssdk.regions.Region) S3Client(software.amazon.awssdk.services.s3.S3Client)

Example 87 with S3Client

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

the class DeleteObjects method deleteBucketObjects.

// snippet-start:[s3.java2.delete_objects.main]
public static void deleteBucketObjects(S3Client s3, String bucketName, String objectName) {
    ArrayList<ObjectIdentifier> toDelete = new ArrayList<ObjectIdentifier>();
    toDelete.add(ObjectIdentifier.builder().key(objectName).build());
    try {
        DeleteObjectsRequest dor = DeleteObjectsRequest.builder().bucket(bucketName).delete(Delete.builder().objects(toDelete).build()).build();
        s3.deleteObjects(dor);
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}
Also used : S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) ArrayList(java.util.ArrayList) ObjectIdentifier(software.amazon.awssdk.services.s3.model.ObjectIdentifier) DeleteObjectsRequest(software.amazon.awssdk.services.s3.model.DeleteObjectsRequest)

Example 88 with S3Client

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

the class GetAcl method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "  <bucketName> <objectKey>\n\n" + "Where:\n" + "  bucketName - the Amazon S3 bucket to get the access control list (ACL) for.\n" + "  objectKey - the object to get the ACL for. \n";
    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucketName = args[0];
    String objectKey = args[1];
    System.out.println("Retrieving ACL for object: " + objectKey);
    System.out.println("in bucket: " + bucketName);
    Region region = Region.US_WEST_2;
    S3Client s3 = S3Client.builder().region(region).build();
    getBucketACL(s3, objectKey, bucketName);
    s3.close();
    System.out.println("Done!");
}
Also used : Region(software.amazon.awssdk.regions.Region) S3Client(software.amazon.awssdk.services.s3.S3Client)

Example 89 with S3Client

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

the class GetObjectContentType method main.

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

Example 90 with S3Client

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

the class GetObjectUrl method getURL.

// snippet-start:[s3.java2.getobjecturl.main]
public static void getURL(S3Client s3, String bucketName, String keyName) {
    try {
        GetUrlRequest request = GetUrlRequest.builder().bucket(bucketName).key(keyName).build();
        URL url = s3.utilities().getUrl(request);
        System.out.println("The URL for  " + keyName + " is " + url.toString());
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : GetUrlRequest(software.amazon.awssdk.services.s3.model.GetUrlRequest) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) URL(java.net.URL)

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