Class S3Template

java.lang.Object
io.awspring.cloud.s3.S3Template
All Implemented Interfaces:
S3Operations

public class S3Template extends Object implements S3Operations
Higher level abstraction over S3Client providing methods for the most common use cases.
Since:
3.0
Author:
Maciej Walkowiak
  • Constructor Details

    • S3Template

      public S3Template(software.amazon.awssdk.services.s3.S3Client s3Client, S3OutputStreamProvider s3OutputStreamProvider, S3ObjectConverter s3ObjectConverter, software.amazon.awssdk.services.s3.presigner.S3Presigner s3Presigner)
  • Method Details

    • createBucket

      public String createBucket(String bucketName)
      Description copied from interface: S3Operations
      Creates a bucket in S3.
      Specified by:
      createBucket in interface S3Operations
      Parameters:
      bucketName - - the bucket name
      Returns:
      created bucket location CreateBucketResponse.location()
    • deleteBucket

      public void deleteBucket(String bucketName)
      Description copied from interface: S3Operations
      Deletes a S3 bucket.
      Specified by:
      deleteBucket in interface S3Operations
      Parameters:
      bucketName - - the bucket name
    • deleteObject

      public void deleteObject(String bucketName, String key)
      Description copied from interface: S3Operations
      Deletes an object from S3 bucket.
      Specified by:
      deleteObject in interface S3Operations
      Parameters:
      bucketName - - the bucket name
      key - - the object key
    • deleteObject

      public void deleteObject(String s3Url)
      Description copied from interface: S3Operations
      Deletes an object from S3 bucket.
      Specified by:
      deleteObject in interface S3Operations
      Parameters:
      s3Url - - the S3 url s3://bucket/key
    • store

      public S3Resource store(String bucketName, String key, Object object)
      Description copied from interface: S3Operations
      Stores a Java object in a S3 bucket. Uses S3ObjectConverter for serialization.
      Specified by:
      store in interface S3Operations
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      object - - the Java object to serialize and store
      Returns:
      created S3Resource.
    • read

      public <T> T read(String bucketName, String key, Class<T> clazz)
      Description copied from interface: S3Operations
      Reads a Java object from a S3 bucket. Uses S3ObjectConverter for deserialization.
      Specified by:
      read in interface S3Operations
      Type Parameters:
      T - - the type of the read object
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      clazz - - the class of the read object
      Returns:
      an object
    • upload

      public S3Resource upload(String bucketName, String key, InputStream inputStream, @Nullable ObjectMetadata objectMetadata)
      Description copied from interface: S3Operations
      Uploads data from an input stream to a S3 bucket.
      Specified by:
      upload in interface S3Operations
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      inputStream - - the input stream
      objectMetadata - - the object metadata
      Returns:
      created S3Resource
    • download

      public S3Resource download(String bucketName, String key)
      Description copied from interface: S3Operations
      Downloads object from S3.
      Specified by:
      download in interface S3Operations
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      Returns:
      downloaded object represented as S3Resource
    • createSignedGetURL

      public URL createSignedGetURL(String bucketName, String key, Duration duration)
      Description copied from interface: S3Operations
      Creates a signed URL for retrieving an object from S3.
      Specified by:
      createSignedGetURL in interface S3Operations
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      duration - - duration that the URL will work
      Returns:
      a URL representing the signed URL
    • createSignedPutURL

      public URL createSignedPutURL(String bucketName, String key, Duration duration, @Nullable ObjectMetadata metadata, @Nullable String contentType)
      Description copied from interface: S3Operations
      Creates a signed URL for putting an object into S3.
      Specified by:
      createSignedPutURL in interface S3Operations
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      duration - - duration that the URL will work
      Returns:
      a URL representing the signed URL