Search in sources :

Example 1 with S3Response

use of com.adeptj.modules.aws.s3.S3Response in project adeptj-modules by AdeptJ.

the class AwsS3Service method createFolder.

/**
 * {@inheritDoc}
 */
@Override
public S3Response createFolder(String bucketName, String folderName) {
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentLength(0);
    try {
        return new S3Response().withPutObjectResult(this.s3Client.putObject(new PutObjectRequest(bucketName, folderName + PATH_SEPARATOR, new ByteArrayInputStream(new byte[0]), objectMetadata)));
    } catch (RuntimeException ex) {
        LOGGER.error("Exception while creating folder!!", ex);
        throw new AwsException(ex.getMessage(), ex);
    }
}
Also used : S3Response(com.adeptj.modules.aws.s3.S3Response) ByteArrayInputStream(java.io.ByteArrayInputStream) AwsException(com.adeptj.modules.aws.core.AwsException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 2 with S3Response

use of com.adeptj.modules.aws.s3.S3Response in project adeptj-modules by AdeptJ.

the class AwsS3Service method uploadFile.

/**
 * {@inheritDoc}
 */
@Override
public S3Response uploadFile(S3Request request) {
    ObjectMetadata objectMetadata = Objects.requireNonNull(request.getMetadata(), OBJ_METADATA_NULL_MSG);
    CannedAccessControlList cannedACL = Objects.requireNonNull(request.getCannedACL(), ACL_NULL_MSG);
    try (InputStream data = Objects.requireNonNull(request.getData(), DATA_NULL_MSG)) {
        return new S3Response().withPutObjectResult(this.s3Client.putObject(new PutObjectRequest(request.getBucketName(), request.getKey(), data, objectMetadata).withCannedAcl(cannedACL)));
    } catch (Exception ex) {
        LOGGER.error("Exception while uploading file!!", ex);
        throw new AwsException(ex.getMessage(), ex);
    }
}
Also used : S3Response(com.adeptj.modules.aws.s3.S3Response) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AwsException(com.adeptj.modules.aws.core.AwsException) CannedAccessControlList(com.amazonaws.services.s3.model.CannedAccessControlList) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) AwsException(com.adeptj.modules.aws.core.AwsException)

Aggregations

AwsException (com.adeptj.modules.aws.core.AwsException)2 S3Response (com.adeptj.modules.aws.s3.S3Response)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)2 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 CannedAccessControlList (com.amazonaws.services.s3.model.CannedAccessControlList)1 InputStream (java.io.InputStream)1