Java Code Examples for com.amazonaws.services.s3.model.ObjectMetadata#getContentType()

The following examples show how to use com.amazonaws.services.s3.model.ObjectMetadata#getContentType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: S3Repository.java    From hawkbit-extensions with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AbstractDbArtifact getArtifactBySha1(final String tenant, final String sha1Hash) {
    final String key = objectKey(tenant, sha1Hash);

    LOG.info("Retrieving S3 object from bucket {} and key {}", s3Properties.getBucketName(), key);
    try (final S3Object s3Object = amazonS3.getObject(s3Properties.getBucketName(), key)) {
        if (s3Object == null) {
            return null;
        }

        final ObjectMetadata s3ObjectMetadata = s3Object.getObjectMetadata();

        // the MD5Content is stored in the ETag
        return new S3Artifact(amazonS3, s3Properties, key, sha1Hash,
                new DbArtifactHash(sha1Hash,
                        BaseEncoding.base16().lowerCase()
                                .encode(BaseEncoding.base64().decode(s3ObjectMetadata.getETag())),
                        null),
                s3ObjectMetadata.getContentLength(), s3ObjectMetadata.getContentType());
    } catch (final IOException e) {
        LOG.error("Could not verify S3Object", e);
        return null;
    }
}