Example usage for com.amazonaws.services.s3 AmazonS3 getBucketPolicy

List of usage examples for com.amazonaws.services.s3 AmazonS3 getBucketPolicy

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3 getBucketPolicy.

Prototype

public BucketPolicy getBucketPolicy(GetBucketPolicyRequest getBucketPolicyRequest)
        throws SdkClientException, AmazonServiceException;

Source Link

Document

Gets the policy for the specified bucket.

Usage

From source file:aws.example.s3.GetBucketPolicy.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    GetBucketPolicy <bucket>\n\n" + "Where:\n"
            + "    bucket - the bucket to get the policy from.\n\n" + "Example:\n"
            + "    GetBucketPolicy testbucket\n\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);//from  w  w w  .  j a v  a2  s .c  om
    }

    String bucket_name = args[0];
    String policy_text = null;

    System.out.format("Getting policy for bucket: \"%s\"\n\n", bucket_name);

    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {
        BucketPolicy bucket_policy = s3.getBucketPolicy(bucket_name);
        policy_text = bucket_policy.getPolicyText();
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }

    if (policy_text == null) {
        System.out.println("The specified bucket has no bucket policy.");
    } else {
        System.out.println("Returned policy:");
        System.out.println("----");
        System.out.println(policy_text);
        System.out.println("----\n");
    }

    System.out.println("Done!");
}

From source file:org.davidmendoza.fileUpload.web.VideoController.java

License:Open Source License

@RequestMapping(value = "/s3", method = RequestMethod.GET)
public String s3(HttpServletRequest req, HttpServletResponse resp) {

    AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
    AmazonS3 s3Client = new AmazonS3Client(credentials);

    BucketPolicy policy = s3Client.getBucketPolicy(bucket);

    return "video/s3";
}