Interface S3Operations

All Known Implementing Classes:
S3Template

public interface S3Operations
Higher level abstraction over S3Client providing methods for the most common use cases. Implemented by S3Template.
Since:
3.0
Author:
Maciej Walkowiak, Ziemowit Stolarczyk
  • Method Details

    • createBucket

      String createBucket(String bucketName)
      Creates a bucket in S3.
      Parameters:
      bucketName - - the bucket name
      Returns:
      created bucket location CreateBucketResponse.location()
    • deleteBucket

      void deleteBucket(String bucketName)
      Deletes a S3 bucket.
      Parameters:
      bucketName - - the bucket name
    • bucketExists

      boolean bucketExists(String bucketName)
      Checks if an S3 bucket exists.
      Parameters:
      bucketName - - the bucket name
      Returns:
      true if bucket exists; false otherwise
    • deleteObject

      void deleteObject(String bucketName, String key)
      Deletes an object from S3 bucket.
      Parameters:
      bucketName - - the bucket name
      key - - the object key
    • deleteObject

      void deleteObject(String s3Url)
      Deletes an object from S3 bucket.
      Parameters:
      s3Url - - the S3 url s3://bucket/key
    • objectExists

      boolean objectExists(String bucketName, String key)
      Checks if an S3 object exists.
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      Returns:
      true if object exists; false otherwise
    • listObjects

      List<S3Resource> listObjects(String bucketName, String prefix)
      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
      Parameters:
      bucketName - - the bucket name
      prefix - - objects prefix
      Returns:
      list of S3Resource
    • store

      S3Resource store(String bucketName, String key, Object object)
      Stores a Java object in a S3 bucket. Uses S3ObjectConverter for serialization.
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      object - - the Java object to serialize and store
      Returns:
      created S3Resource.
    • createResource

      S3Resource createResource(String bucketName, String key)
      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.

      Parameters:
      bucketName - - the bucket name
      key - - the object key
      Returns:
      the S3Resource
    • read

      <T> T read(String bucketName, String key, Class<T> clazz)
      Reads a Java object from a S3 bucket. Uses S3ObjectConverter for deserialization.
      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

      S3Resource upload(String bucketName, String key, InputStream inputStream, @Nullable ObjectMetadata objectMetadata)
      Uploads data from an input stream to a S3 bucket.
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      inputStream - - the input stream
      objectMetadata - - the object metadata
      Returns:
      created S3Resource
    • upload

      default S3Resource upload(String bucketName, String key, InputStream inputStream)
      Uploads data from an input stream to a S3 bucket.
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      inputStream - - the input stream
      Returns:
      created S3Resource
    • download

      S3Resource download(String bucketName, String key)
      Downloads object from S3.
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      Returns:
      downloaded object represented as S3Resource
    • createSignedGetURL

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

      URL createSignedPutURL(String bucketName, String key, Duration duration, @Nullable ObjectMetadata metadata, @Nullable String contentType)
      Creates a signed URL for putting an object into S3.
      Parameters:
      bucketName - - the bucket name
      key - - the object key
      duration - - duration that the URL will work
      Returns:
      a URL representing the signed URL
    • createSignedPutURL

      default URL createSignedPutURL(String bucketName, String key, Duration duration)