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, Ziemowit Stolarczyk
  • 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
    • bucketExists

      public boolean bucketExists(String bucketName)
      Description copied from interface: S3Operations
      Checks if an S3 bucket exists.
      Specified by:
      bucketExists in interface S3Operations
      Parameters:
      bucketName - - the bucket name
      Returns:
      true if bucket exists; false otherwise
    • 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
    • objectExists

      public boolean objectExists(String bucketName, String key)
      Description copied from interface: S3Operations
      Checks if an S3 object exists.
      Specified by:
      objectExists in interface S3Operations
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      Returns:
      true if object exists; false otherwise
    • listObjects

      public List<S3Resource> listObjects(String bucketName, String prefix)
      Description copied from interface: S3Operations
      Returns some or all (up to 1,000) of the objects in a bucket. Does not handle pagination. If you need pagination you should use S3PathMatchingResourcePatternResolver or S3Client
      Specified by:
      listObjects in interface S3Operations
      Parameters:
      bucketName - - the bucket name
      prefix - - objects prefix
      Returns:
      list of S3Resource
    • 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.
    • createResource

      public S3Resource createResource(String bucketName, String key)
      Description copied from interface: S3Operations
      Creates an S3Resource for given bucket name and object key using S3OutputStreamProvider configured on the implementation class (S3Template).

      Note that calling this method does not create an actual object on S3.

      Specified by:
      createResource in interface S3Operations
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      Returns:
      the 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