Search in sources :

Example 61 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project iudx-resource-server by datakaveri.

the class S3FileOpsHelper method s3Upload.

public void s3Upload(File file, String objectKey, Handler<AsyncResult<JsonObject>> handler) {
    DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain();
    try {
        AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(clientRegion).withCredentials(credentialProviderChain).build();
        TransferManager tm = TransferManagerBuilder.standard().withS3Client(s3Client).build();
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentDisposition("attachment; filename=" + file.getName());
        objectMetadata.setContentLength(file.length());
        // TransferManager processes all transfers asynchronously,
        // so this call returns immediately.
        Upload upload = tm.upload(bucketName, objectKey, new FileInputStream(file), objectMetadata);
        LOGGER.info("Object upload started");
        // upload.addProgressListener(uploadProgressListener);
        upload.waitForCompletion();
        LOGGER.info("Object upload complete");
        ZonedDateTime zdt = ZonedDateTime.now();
        zdt = zdt.plusDays(1);
        Long expiry = zdt.toEpochSecond() * 1000;
        JsonObject result = new JsonObject().put("s3_url", generatePreSignedUrl(expiry, objectKey)).put("expiry", zdt.toLocalDateTime().toString()).put("object_id", objectKey);
        handler.handle(Future.succeededFuture(result));
    } catch (AmazonServiceException e) {
        // The call was transmitted successfully, but Amazon S3 couldn't process
        // it, so it returned an error response.
        LOGGER.error(e);
        handler.handle(Future.failedFuture(e));
    } catch (AmazonClientException e) {
        LOGGER.error(e);
        handler.handle(Future.failedFuture(e));
    } catch (InterruptedException e) {
        LOGGER.error(e);
        handler.handle(Future.failedFuture(e));
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        handler.handle(Future.failedFuture(e));
    }
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AmazonS3(com.amazonaws.services.s3.AmazonS3) TransferManager(com.amazonaws.services.s3.transfer.TransferManager) AmazonClientException(com.amazonaws.AmazonClientException) FileNotFoundException(java.io.FileNotFoundException) Upload(com.amazonaws.services.s3.transfer.Upload) JsonObject(io.vertx.core.json.JsonObject) FileInputStream(java.io.FileInputStream) ZonedDateTime(java.time.ZonedDateTime) AmazonServiceException(com.amazonaws.AmazonServiceException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 62 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project geowebcache by GeoWebCache.

the class S3BlobStore method delete.

@Override
public boolean delete(TileObject obj) throws StorageException {
    final String key = keyBuilder.forTile(obj);
    // don't bother for the extra call if there are no listeners
    if (listeners.isEmpty()) {
        return s3Ops.deleteObject(key);
    }
    ObjectMetadata oldObj = s3Ops.getObjectMetadata(key);
    if (oldObj == null) {
        return false;
    }
    s3Ops.deleteObject(key);
    obj.setBlobSize((int) oldObj.getContentLength());
    listeners.sendTileDeleted(obj);
    return true;
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 63 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project geowebcache by GeoWebCache.

the class S3BlobStore method put.

@Override
public void put(TileObject obj) throws StorageException {
    final Resource blob = obj.getBlob();
    checkNotNull(blob);
    checkNotNull(obj.getBlobFormat());
    final String key = keyBuilder.forTile(obj);
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentLength(blob.getSize());
    String blobFormat = obj.getBlobFormat();
    String mimeType;
    try {
        mimeType = MimeType.createFromFormat(blobFormat).getMimeType();
    } catch (MimeException me) {
        throw new RuntimeException(me);
    }
    objectMetadata.setContentType(mimeType);
    // don't bother for the extra call if there are no listeners
    final boolean existed;
    ObjectMetadata oldObj;
    if (listeners.isEmpty()) {
        existed = false;
        oldObj = null;
    } else {
        oldObj = s3Ops.getObjectMetadata(key);
        existed = oldObj != null;
    }
    final ByteArrayInputStream input = toByteArray(blob);
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, input, objectMetadata).withCannedAcl(acl);
    log.trace(log.isTraceEnabled() ? ("Storing " + key) : "");
    s3Ops.putObject(putObjectRequest);
    putParametersMetadata(obj.getLayerName(), obj.getParametersId(), obj.getParameters());
    /*
         * This is important because listeners may be tracking tile existence
         */
    if (!listeners.isEmpty()) {
        if (existed) {
            long oldSize = oldObj.getContentLength();
            listeners.sendTileUpdated(obj, oldSize);
        } else {
            listeners.sendTileStored(obj);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(org.geowebcache.io.Resource) ByteArrayResource(org.geowebcache.io.ByteArrayResource) MimeException(org.geowebcache.mime.MimeException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 64 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project geowebcache by GeoWebCache.

the class S3Ops method putProperties.

public void putProperties(String resourceKey, Properties properties) throws StorageException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        properties.store(out, "");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    byte[] bytes = out.toByteArray();
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentLength(bytes.length);
    objectMetadata.setContentType("text/plain");
    InputStream in = new ByteArrayInputStream(bytes);
    PutObjectRequest putReq = new PutObjectRequest(bucketName, resourceKey, in, objectMetadata);
    putObject(putReq);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 65 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project mojito by box.

the class S3BlobStorage method put.

@Override
public void put(String name, String content, Retention retention) {
    byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentType("text/plain");
    objectMetadata.setContentEncoding(StandardCharsets.UTF_8.toString());
    put(name, bytes, retention, objectMetadata);
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)566 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)191 ByteArrayInputStream (java.io.ByteArrayInputStream)157 Test (org.junit.Test)143 IOException (java.io.IOException)101 InputStream (java.io.InputStream)80 File (java.io.File)62 AmazonClientException (com.amazonaws.AmazonClientException)61 AmazonServiceException (com.amazonaws.AmazonServiceException)61 S3Object (com.amazonaws.services.s3.model.S3Object)59 AmazonS3 (com.amazonaws.services.s3.AmazonS3)54 Date (java.util.Date)46 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)34 GetObjectMetadataRequest (com.amazonaws.services.s3.model.GetObjectMetadataRequest)33 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)32 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)30 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)29 Upload (com.amazonaws.services.s3.transfer.Upload)26 SdkClientException (com.amazonaws.SdkClientException)24 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)24