List of usage examples for com.amazonaws.services.s3.model PutObjectRequest withCannedAcl
@Override @SuppressWarnings("unchecked") public PutObjectRequest withCannedAcl(CannedAccessControlList cannedAcl)
From source file:br.puc_rio.ele.lvc.interimage.common.udf.ROIStorage.java
License:Apache License
/** * Method invoked on every tuple during foreach evaluation. * @param input tuple<br>// w ww . j a v a 2 s . c o m * first column is assumed to have the geometry<br> * second column is assumed to have the class name<br> * third column is assumed to have the output path * @exception java.io.IOException * @return true if successful, false otherwise */ @Override public Boolean exec(Tuple input) throws IOException { if (input == null || input.size() < 3) return null; try { Object objGeometry = input.get(0); Geometry geometry = _geometryParser.parseGeometry(objGeometry); String className = DataType.toString(input.get(1)); String path = DataType.toString(input.get(2)); AWSCredentials credentials = new BasicAWSCredentials(_accessKey, _secretKey); AmazonS3 conn = new AmazonS3Client(credentials); conn.setEndpoint("https://s3.amazonaws.com"); /*File temp = File.createTempFile(className, ".wkt"); // Delete temp file when program exits. temp.deleteOnExit(); BufferedWriter out = new BufferedWriter(new FileWriter(temp)); out.write(new WKTWriter().write(geometry)); out.close();*/ /* File temp = File.createTempFile(className, ".wkt.snappy"); temp.deleteOnExit();*/ String geom = new WKTWriter().write(geometry); ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputStream snappyOut = new SnappyOutputStream(out); snappyOut.write(geom.getBytes()); snappyOut.close(); /*PutObjectRequest putObjectRequest = new PutObjectRequest(_bucket, path + className + ".wkt.snappy", temp); putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all*/ PutObjectRequest putObjectRequest = new PutObjectRequest(_bucket, path + className + ".wkts", new ByteArrayInputStream(out.toByteArray()), new ObjectMetadata()); putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all TransferManager tx = new TransferManager(credentials); tx.upload(putObjectRequest); return true; } catch (Exception e) { throw new IOException("Caught exception processing input row ", e); } }
From source file:br.puc_rio.ele.lvc.interimage.core.datamanager.AWSSource.java
License:Apache License
public void put(String from, String to, Resource resource) { try {// w ww . j a va2s .com File file = new File(from); PutObjectRequest putObjectRequest = new PutObjectRequest(_bucket, to, file); if (resource instanceof SplittableResource) { SplittableResource rsrc = (SplittableResource)resource; if (rsrc.getType() == SplittableResource.IMAGE) { putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all } } else if (resource instanceof DefaultResource) { DefaultResource rsrc = (DefaultResource)resource; if (rsrc.getType() == DefaultResource.TILE) { putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all } else if (rsrc.getType() == DefaultResource.FUZZY_SET) { putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all } else if (rsrc.getType() == DefaultResource.SHAPE) { putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all } } Upload upload = _manager.upload(putObjectRequest); upload.waitForCompletion(); System.out.println("AWSSource: Uploaded file - " + to); } catch (Exception e) { System.err.println("Source put failed: " + e.getMessage()); } }
From source file:br.puc_rio.ele.lvc.interimage.core.datamanager.AWSSource.java
License:Apache License
public void put(String from, String to, Resource resource) { try {/*from w w w. j a va 2s .c om*/ File file = new File(from); PutObjectRequest putObjectRequest = new PutObjectRequest(_bucket, to, file); if (resource instanceof SplittableResource) { SplittableResource rsrc = (SplittableResource) resource; if (rsrc.getType() == SplittableResource.IMAGE) { putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all } } else if (resource instanceof DefaultResource) { DefaultResource rsrc = (DefaultResource) resource; if (rsrc.getType() == DefaultResource.TILE) { putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all } else if (rsrc.getType() == DefaultResource.FUZZY_SET) { putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all } else if (rsrc.getType() == DefaultResource.SHAPE) { putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all } } Upload upload = _manager.upload(putObjectRequest); upload.waitForCompletion(); System.out.println("AWSSource: Uploaded file - " + to); } catch (Exception e) { System.err.println("Source put failed: " + e.getMessage()); } }
From source file:com.digitaslbi.helios.utils.S3Helper.java
public static void uploadFile(String fileName, byte[] content) { connect();// ww w .jav a 2s. com ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(content.length); try { log.info("[S3Helper][uploadFile] Uploading a new object to S3: " + fileName); PutObjectRequest putObjectRequest = new PutObjectRequest(S3Properties.getInstance().getBucketName(), fileName, new ByteArrayInputStream(content), metadata); putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); s3Client.putObject(putObjectRequest); } catch (AmazonServiceException ase) { log.error("[S3Helper][uploadFile] Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); log.error("Error Message: " + ase.getMessage()); log.error("HTTP Status Code: " + ase.getStatusCode()); log.error("AWS Error Code: " + ase.getErrorCode()); log.error("Error Type: " + ase.getErrorType()); log.error("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { log.error("[S3Helper][uploadFile] 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."); log.error("Error Message: " + ace.getMessage()); } }
From source file:com.vanilla.transmilenio.servicio.AmazonServicio.java
public String guardarArchivo(File file, String nombreArchivo) { PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, nombreArchivo, file); putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); s3client.putObject(putObjectRequest); String url = "https://s3.amazonaws.com/" + bucketName + "/" + nombreArchivo; return url;//from w w w .ja v a 2 s . c om }
From source file:com.vanilla.transmilenio.servicio.AmazonServicio.java
public String guardarArchivo(InputStream input, String nombreArchivo) { PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, nombreArchivo, input, new ObjectMetadata()); putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); s3client.putObject(putObjectRequest); String url = "https://s3.amazonaws.com/" + bucketName + "/" + nombreArchivo; return url;/*from w ww. j av a2 s .c o m*/ }
From source file:com.zero_x_baadf00d.play.module.aws.s3.ebean.BaseS3FileModel.java
License:Open Source License
/** * Save the current object. The file will be uploaded to PlayS3 bucket. * * @since 16.03.13// ww w . j av a2 s .c o m */ @Override public void save() { if (this.id == null) { this.id = Generators.timeBasedGenerator().generate(); } if (!PlayS3.isReady()) { Logger.error("Could not save PlayS3 file because amazonS3 variable is null"); throw new RuntimeException("Could not save"); } else { this.bucket = PlayS3.getBucketName(); if (this.subDirectory == null) { this.subDirectory = ""; } this.subDirectory = this.subDirectory.trim(); // Set cache control and server side encryption final ObjectMetadata objMetaData = new ObjectMetadata(); objMetaData.setContentType(this.contentType); objMetaData.setCacheControl("max-age=315360000, public"); objMetaData.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); try { objMetaData.setContentLength(this.objectData.available()); } catch (final IOException ex) { Logger.warn("Can't retrieve stream available size", ex); } finally { try { if (this.objectData.markSupported()) { this.objectData.reset(); } } catch (final IOException ex) { Logger.error("Can't reset stream position", ex); } } // Upload file to PlayS3 final PutObjectRequest putObjectRequest = new PutObjectRequest(this.bucket, this.getActualFileName(), this.objectData, objMetaData); putObjectRequest.withCannedAcl( this.isPrivate ? CannedAccessControlList.Private : CannedAccessControlList.PublicRead); PlayS3.getAmazonS3().putObject(putObjectRequest); try { if (this.objectData != null) { this.objectData.close(); } } catch (final IOException ignore) { } // Save object on database super.save(); } }
From source file:cz.pichlik.goodsentiment.server.repository.S3RepositoryBase.java
License:Apache License
public void save(final String bucket, String key, File file, boolean publicRead) { PutObjectRequest req = new PutObjectRequest(bucket, key, file); if (publicRead) { req.withCannedAcl(CannedAccessControlList.PublicRead); }/*w w w . j a v a 2s. c o m*/ s3Client.putObject(req); }
From source file:io.stallion.services.S3StorageService.java
License:Open Source License
public void uploadFile(File file, String bucket, String fileKey, boolean isPublic, String contentType, Map<String, String> headers) { client.putObject(bucket, fileKey, file); PutObjectRequest req = new PutObjectRequest(bucket, fileKey, file); if (isPublic) { req.withCannedAcl(CannedAccessControlList.PublicRead); }/*www . j a v a 2 s.c om*/ ObjectMetadata meta = new ObjectMetadata(); if (headers != null) { for (String key : headers.keySet()) { meta.setHeader(key, headers.get(key)); } } if (!empty(contentType)) { meta.setContentType(contentType); } req.setMetadata(meta); client.putObject(req); }
From source file:ohnosequences.ivy.S3Repository.java
License:Apache License
@Override protected void put(File source, String destination, boolean overwrite) { //System.out.print("parent> "); String bucket = S3Utils.getBucket(destination); String key = S3Utils.getKey(destination); // System.out.println("publishing: bucket=" + bucket + " key=" + key); PutObjectRequest request = new PutObjectRequest(bucket, key, source); request = request.withCannedAcl(acl); if (serverSideEncryption) { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); request.setMetadata(objectMetadata); }//from w w w . j a v a 2 s .c o m if (!getS3Client().doesBucketExist(bucket)) { if (!createBucket(bucket, region)) { throw new Error("couldn't create bucket"); } } if (!this.overwrite && !getS3Client().listObjects(bucket, key).getObjectSummaries().isEmpty()) { throw new Error(destination + " exists but overwriting is disabled"); } getS3Client().putObject(request); }