Search in sources :

Example 1 with Mimetypes

use of com.amazonaws.services.s3.util.Mimetypes in project studio by craftercms.

the class AwsS3ServiceImpl method listItems.

/**
 * {@inheritDoc}
 */
@Override
@HasPermission(type = DefaultPermission.class, action = "s3 read")
public List<S3Item> listItems(@ValidateStringParam(name = "siteId") @ProtectedResourceId("siteId") String siteId, @ValidateStringParam(name = "profileId") String profileId, @ValidateStringParam(name = "path") String path, @ValidateStringParam(name = "type") String type) throws AwsException {
    S3Profile profile = getProfile(siteId, profileId);
    AmazonS3 client = getS3Client(profile);
    List<S3Item> items = new LinkedList<>();
    Mimetypes mimetypes = Mimetypes.getInstance();
    MimeType filerType = StringUtils.isEmpty(type) || StringUtils.equals(type, ITEM_FILTER) ? MimeTypeUtils.ALL : new MimeType(type);
    String prefix = StringUtils.isEmpty(path) ? path : normalizePrefix(path);
    ListObjectsV2Request request = new ListObjectsV2Request().withBucketName(profile.getBucketName()).withPrefix(prefix).withDelimiter(delimiter);
    ListObjectsV2Result result;
    do {
        result = client.listObjectsV2(request);
        result.getCommonPrefixes().stream().map(p -> new S3Item(StringUtils.removeEnd(StringUtils.removeStart(p, prefix), delimiter), p, true)).forEach(items::add);
        result.getObjectSummaries().stream().filter(o -> !StringUtils.equals(o.getKey(), prefix) && MimeType.valueOf(mimetypes.getMimetype(o.getKey())).isCompatibleWith(filerType)).map(o -> new S3Item(StringUtils.removeStart(o.getKey(), prefix), createUrl(profileId, o.getKey()), false)).forEach(items::add);
        request.setContinuationToken(result.getNextContinuationToken());
    } while (result.isTruncated());
    return items;
}
Also used : S3Item(org.craftercms.studio.model.aws.s3.S3Item) AwsUtils(org.craftercms.studio.impl.v1.service.aws.AwsUtils) S3Item(org.craftercms.studio.model.aws.s3.S3Item) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission) AbstractAwsService(org.craftercms.studio.api.v1.service.aws.AbstractAwsService) AwsS3Service(org.craftercms.studio.api.v2.service.aws.s3.AwsS3Service) S3Profile(org.craftercms.commons.config.profiles.aws.S3Profile) StringUtils.stripStart(org.apache.commons.lang3.StringUtils.stripStart) ProtectedResourceId(org.craftercms.commons.security.permissions.annotations.ProtectedResourceId) MimeTypeUtils(org.springframework.util.MimeTypeUtils) StringUtils.appendIfMissing(org.apache.commons.lang3.StringUtils.appendIfMissing) StringUtils(org.apache.commons.lang3.StringUtils) ListObjectsV2Result(com.amazonaws.services.s3.model.ListObjectsV2Result) MimeType(org.springframework.util.MimeType) ListObjectsV2Request(com.amazonaws.services.s3.model.ListObjectsV2Request) AwsException(org.craftercms.studio.api.v1.exception.AwsException) List(java.util.List) Mimetypes(com.amazonaws.services.s3.internal.Mimetypes) S3ClientCachingFactory(org.craftercms.commons.aws.S3ClientCachingFactory) AmazonS3(com.amazonaws.services.s3.AmazonS3) DefaultPermission(org.craftercms.commons.security.permissions.DefaultPermission) Required(org.springframework.beans.factory.annotation.Required) ValidateStringParam(org.craftercms.commons.validation.annotations.param.ValidateStringParam) LinkedList(java.util.LinkedList) InputStream(java.io.InputStream) AmazonS3(com.amazonaws.services.s3.AmazonS3) ListObjectsV2Request(com.amazonaws.services.s3.model.ListObjectsV2Request) ListObjectsV2Result(com.amazonaws.services.s3.model.ListObjectsV2Result) Mimetypes(com.amazonaws.services.s3.internal.Mimetypes) S3Profile(org.craftercms.commons.config.profiles.aws.S3Profile) LinkedList(java.util.LinkedList) MimeType(org.springframework.util.MimeType) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 2 with Mimetypes

use of com.amazonaws.services.s3.util.Mimetypes in project aws-sdk-android by aws-amplify.

the class EncryptionUtils method updateMetadataWithEncryptionInstruction.

/**
 * Update the request's ObjectMetadata with the necessary information for
 * decrypting the object
 *
 * @param request Non-null PUT request encrypted using the given instruction
 * @param instruction Non-null instruction used to encrypt the data in this
 *            PUT request.
 */
public static void updateMetadataWithEncryptionInstruction(PutObjectRequest request, EncryptionInstruction instruction) {
    byte[] keyBytesToStoreInMetadata = instruction.getEncryptedSymmetricKey();
    Cipher symmetricCipher = instruction.getSymmetricCipher();
    Map<String, String> materialsDescription = instruction.getMaterialsDescription();
    ObjectMetadata metadata = request.getMetadata();
    if (metadata == null)
        metadata = new ObjectMetadata();
    if (request.getFile() != null) {
        Mimetypes mimetypes = Mimetypes.getInstance();
        metadata.setContentType(mimetypes.getMimetype(request.getFile()));
    }
    updateMetadata(metadata, keyBytesToStoreInMetadata, symmetricCipher, materialsDescription);
    request.setMetadata(metadata);
}
Also used : Mimetypes(com.amazonaws.services.s3.util.Mimetypes) Cipher(javax.crypto.Cipher) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 3 with Mimetypes

use of com.amazonaws.services.s3.util.Mimetypes in project aws-sdk-android by aws-amplify.

the class S3CryptoModuleBase method updateMetadataWithContentCryptoMaterial.

protected final ObjectMetadata updateMetadataWithContentCryptoMaterial(ObjectMetadata metadata, File file, ContentCryptoMaterial instruction) {
    if (metadata == null) {
        metadata = new ObjectMetadata();
    }
    if (file != null) {
        final Mimetypes mimetypes = Mimetypes.getInstance();
        metadata.setContentType(mimetypes.getMimetype(file));
    }
    return instruction.toObjectMetadata(metadata, cryptoConfig.getCryptoMode());
}
Also used : Mimetypes(com.amazonaws.services.s3.util.Mimetypes) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) ObjectMetadata(com.amazonaws.services.s3.model.CryptoStorageMode.ObjectMetadata)

Example 4 with Mimetypes

use of com.amazonaws.services.s3.util.Mimetypes in project tbbtalentv2 by talentbeyondboundaries.

the class S3ResourceHelper method addObjectMetadata.

public void addObjectMetadata(S3ObjectSummary objectSummary) {
    ObjectMetadata metadata = new ObjectMetadata();
    Mimetypes mimetypes = Mimetypes.getInstance();
    metadata.setContentType(mimetypes.getMimetype(objectSummary.getKey()));
    final CopyObjectRequest request = new CopyObjectRequest(objectSummary.getBucketName(), objectSummary.getKey(), objectSummary.getBucketName(), objectSummary.getKey()).withSourceBucketName(objectSummary.getBucketName()).withSourceKey(objectSummary.getKey()).withNewObjectMetadata(metadata);
    amazonS3.copyObject(request);
}
Also used : Mimetypes(com.amazonaws.services.s3.internal.Mimetypes)

Aggregations

Mimetypes (com.amazonaws.services.s3.internal.Mimetypes)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)2 Mimetypes (com.amazonaws.services.s3.util.Mimetypes)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 ObjectMetadata (com.amazonaws.services.s3.model.CryptoStorageMode.ObjectMetadata)1 ListObjectsV2Request (com.amazonaws.services.s3.model.ListObjectsV2Request)1 ListObjectsV2Result (com.amazonaws.services.s3.model.ListObjectsV2Result)1 InputStream (java.io.InputStream)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Cipher (javax.crypto.Cipher)1 StringUtils (org.apache.commons.lang3.StringUtils)1 StringUtils.appendIfMissing (org.apache.commons.lang3.StringUtils.appendIfMissing)1 StringUtils.stripStart (org.apache.commons.lang3.StringUtils.stripStart)1 S3ClientCachingFactory (org.craftercms.commons.aws.S3ClientCachingFactory)1 S3Profile (org.craftercms.commons.config.profiles.aws.S3Profile)1 DefaultPermission (org.craftercms.commons.security.permissions.DefaultPermission)1 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)1 ProtectedResourceId (org.craftercms.commons.security.permissions.annotations.ProtectedResourceId)1 ValidateStringParam (org.craftercms.commons.validation.annotations.param.ValidateStringParam)1