Example usage for com.amazonaws.services.s3.model ObjectMetadata setHttpExpiresDate

List of usage examples for com.amazonaws.services.s3.model ObjectMetadata setHttpExpiresDate

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model ObjectMetadata setHttpExpiresDate.

Prototype

public void setHttpExpiresDate(Date httpExpiresDate) 

Source Link

Document

Set the date when the object is no longer cacheable.

Usage

From source file:com.emc.ecs.sync.util.AwsS3Util.java

License:Open Source License

public static ObjectMetadata s3MetaFromSyncMeta(SyncMetadata syncMeta) {
    ObjectMetadata om = new ObjectMetadata();
    if (syncMeta.getCacheControl() != null)
        om.setCacheControl(syncMeta.getCacheControl());
    if (syncMeta.getContentDisposition() != null)
        om.setContentDisposition(syncMeta.getContentDisposition());
    if (syncMeta.getContentEncoding() != null)
        om.setContentEncoding(syncMeta.getContentEncoding());
    om.setContentLength(syncMeta.getContentLength());
    if (syncMeta.getChecksum() != null && syncMeta.getChecksum().getAlgorithm().equals("MD5"))
        om.setContentMD5(syncMeta.getChecksum().getValue());
    if (syncMeta.getContentType() != null)
        om.setContentType(syncMeta.getContentType());
    if (syncMeta.getHttpExpires() != null)
        om.setHttpExpiresDate(syncMeta.getHttpExpires());
    om.setUserMetadata(formatUserMetadata(syncMeta));
    if (syncMeta.getModificationTime() != null)
        om.setLastModified(syncMeta.getModificationTime());
    return om;/*from   w ww .j  a  v a  2  s .  c  o  m*/
}

From source file:com.sangupta.urn.service.impl.AmazonS3UrnStorageServiceImpl.java

License:Apache License

@Override
protected String save(UrnObject urnObject) {
    InputStream stream = new ByteArrayInputStream(urnObject.bytes);

    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(urnObject.bytes.length);

    if (AssertUtils.isNotEmpty(urnObject.name)) {
        metadata.setContentDisposition("filename=" + urnObject.name);
    }// w w  w .  jav a2 s. c  om

    if (AssertUtils.isNotEmpty(urnObject.mime)) {
        metadata.setContentType(urnObject.mime);
    }

    if (urnObject.expiry > 0) {
        metadata.setHttpExpiresDate(new Date(urnObject.expiry));
    }

    PutObjectResult result = this.client.putObject(this.bucketName, urnObject.key, stream, metadata);
    if (result == null) {
        return null;
    }

    return this.client.getResourceUrl(this.bucketName, urnObject.key);
}

From source file:jenkins.plugins.itemstorage.s3.S3BaseUploadCallable.java

License:Open Source License

protected ObjectMetadata buildMetadata(File file) throws IOException {
    final ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentType(Mimetypes.getInstance().getMimetype(file.getName()));
    metadata.setContentLength(file.length());
    metadata.setLastModified(new Date(file.lastModified()));

    if (storageClass != null && !storageClass.isEmpty()) {
        metadata.setHeader("x-amz-storage-class", storageClass);
    }//from w ww . ja va2s.  co  m
    if (useServerSideEncryption) {
        metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
    }

    for (Map.Entry<String, String> entry : userMetadata.entrySet()) {
        final String key = entry.getKey().toLowerCase();
        switch (key) {
        case "cache-control":
            metadata.setCacheControl(entry.getValue());
            break;
        case "expires":
            try {
                final Date expires = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z")
                        .parse(entry.getValue());
                metadata.setHttpExpiresDate(expires);
            } catch (ParseException e) {
                metadata.addUserMetadata(entry.getKey(), entry.getValue());
            }
            break;
        case "content-encoding":
            metadata.setContentEncoding(entry.getValue());
            break;
        case "content-type":
            metadata.setContentType(entry.getValue());
        default:
            metadata.addUserMetadata(entry.getKey(), entry.getValue());
            break;
        }
    }
    return metadata;
}