List of usage examples for com.amazonaws.services.s3.model CannedAccessControlList PublicReadWrite
CannedAccessControlList PublicReadWrite
To view the source code for com.amazonaws.services.s3.model CannedAccessControlList PublicReadWrite.
Click Source Link
From source file:com.mindtree.maven.S3Mojo.java
License:Apache License
private void createBucketAndUploadFiles() throws MojoExecutionException { for (int i = 0; i < bucketNames.length; i++) { String path = bucketNames[i]; int index = path.indexOf("/"); logger.debug("Got index of / : " + index); logger.debug("Trying upload for files with path : " + path); // The path to upload can have subdirectories hence only the first // directory (root) is required String rootBucket = path; if (index == 0) { logger.debug("Unique name bucket creation is required"); rootBucket = UNIQUE;//from w w w. j a va 2 s . c o m } else if (index != -1) { logger.debug("Given name bucket creation is required"); rootBucket = rootBucket.substring(0, index); } Bucket bucket = createS3Bucket(rootBucket); if (bucket != null) { List<File> fileList = mapFiles.get(path); logger.debug("Got fileList as null :: " + (fileList == null)); if (fileList != null) { logger.debug("Size of fileList :" + fileList.size()); } CannedAccessControlList cacl = CannedAccessControlList.Private; if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.AuthenticatedRead.toString())) { cacl = CannedAccessControlList.AuthenticatedRead; } else if (accessControls[i] .equalsIgnoreCase(CannedAccessControlList.BucketOwnerFullControl.toString())) { cacl = CannedAccessControlList.BucketOwnerFullControl; } else if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.BucketOwnerRead.toString())) { cacl = CannedAccessControlList.BucketOwnerRead; } else if (accessControls[i] .equalsIgnoreCase(CannedAccessControlList.LogDeliveryWrite.toString())) { cacl = CannedAccessControlList.LogDeliveryWrite; } else if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.Private.toString())) { cacl = CannedAccessControlList.Private; } else if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.PublicRead.toString())) { cacl = CannedAccessControlList.PublicRead; } else if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.PublicReadWrite.toString())) { cacl = CannedAccessControlList.PublicReadWrite; } String bucketName = bucket.getName() + bucketNames[i].substring(bucketNames[i].indexOf("/")); logger.debug("File to upload to :" + bucketName); if (fileList != null && fileList.size() > 0) { if (!retainFolderStructure) { logger.debug("Not retaining folder structure and uploadinf files"); System.out.println(cacl.toString()); List<PutObjectResult> fileUploadResults = S3Helper.uploadFiles(fileList, bucketName, s3, cacl); } else { logger.debug("Uploading with retained dir structure"); List<PutObjectResult> fileUploadResults = S3Helper.uploadFiles(fileList, bucketName, s3, cacl, root); } } } } }
From source file:iit.edu.supadyay.s3.S3upload.java
public static boolean upload(String bucketName, String uploadFileName, String keyName) throws IOException, InterruptedException { //access = "AKIAJ2YSLRUZR5B3F5HQ"; //secret = "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"; //AWSCredentials credentials = new BasicAWSCredentials(access, secret); //AmazonS3 s3client = new AmazonS3Client(getCredentials()); AmazonS3 s3client = new AmazonS3Client(new InstanceProfileCredentialsProvider()); try {// w w w . j a va 2s. c om System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFileName); System.out.println("I am before here\n"); s3client.createBucket(bucketName); System.out.println("I am here\n"); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); s3client.setObjectAcl(bucketName, keyName, CannedAccessControlList.PublicReadWrite); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); return false; } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); return false; } return true; }
From source file:org.alanwilliamson.amazon.AmazonKey.java
License:Open Source License
/** * private | public-read | public-read-write | authenticated-read | bucket-owner-read | bucket-owner-full-control | log-delivery-write * * @param acl/*www.j a v a2 s . c o m*/ * @return */ public CannedAccessControlList getAmazonCannedAcl(String acl) { if (acl.equalsIgnoreCase("private")) return CannedAccessControlList.Private; else if (acl.equalsIgnoreCase("public-read") || acl.equalsIgnoreCase("publicread")) return CannedAccessControlList.PublicRead; else if (acl.equalsIgnoreCase("public-read-write") || acl.equalsIgnoreCase("publicreadwrite")) return CannedAccessControlList.PublicReadWrite; else if (acl.equalsIgnoreCase("authenticated-read") || acl.equalsIgnoreCase("authenticatedread")) return CannedAccessControlList.AuthenticatedRead; else if (acl.equalsIgnoreCase("bucket-owner-read") || acl.equalsIgnoreCase("bucketownerread")) return CannedAccessControlList.BucketOwnerRead; else if (acl.equalsIgnoreCase("bucket-owner-full-control") || acl.equalsIgnoreCase("bucketownerfullcontrol")) return CannedAccessControlList.BucketOwnerFullControl; else if (acl.equalsIgnoreCase("log-delivery-write") || acl.equalsIgnoreCase("logdeliverywrite")) return CannedAccessControlList.LogDeliveryWrite; else return CannedAccessControlList.Private; }
From source file:org.springframework.aws.ivy.S3Repository.java
License:Apache License
public void setAcl(String acl) { if ("PRIVATE".equals(acl)) { this.acl = CannedAccessControlList.Private; } else if ("PUBLIC_READ".equals(acl)) { this.acl = CannedAccessControlList.PublicRead; } else if ("PUBLIC_READ_WRITE".equals(acl)) { this.acl = CannedAccessControlList.PublicReadWrite; } else if ("AUTHENTICATED_READ".equals(acl)) { this.acl = CannedAccessControlList.AuthenticatedRead; } else {/*from ww w .ja v a2 s. com*/ throw new IllegalArgumentException("Unknown acl " + acl); } }