Class S3StorageProvider

java.lang.Object
dev.jensderuiter.minecraft_imagery.storage.S3StorageProvider
All Implemented Interfaces:
StorageProvider

public class S3StorageProvider extends Object implements StorageProvider
  • Constructor Details

    • S3StorageProvider

      public S3StorageProvider(String endpoint, String region, String accessKey, String secretKey, String bucket)
      Initialize the S3 storage provider.
      Parameters:
      endpoint - S3 endpoint url.
      region - S3 region (auto for CloudFlare R2).
      accessKey - S3 access key.
      secretKey - S3 secret key.
      bucket - S3 bucket.
  • Method Details

    • fetch

      public BufferedImage fetch(UUID uuid) throws StorageException
      Fetch an image from the S3 bucket. Image is in PNG format (TYPE_INT_ARGB).
      Specified by:
      fetch in interface StorageProvider
      Parameters:
      uuid - The UUID of the image to fetch. You have saved this from the store method.
      Returns:
      The image with the specified UUID.
      Throws:
      StorageException - When the fetching fails.
    • store

      public UUID store(BufferedImage image) throws StorageException
      Store an image in the S3 bucket. Will be stored as (generated uuid).png
      Specified by:
      store in interface StorageProvider
      Parameters:
      image - The image to store.
      Returns:
      The UUID of the image you've just stored. Used to retrieve or remove the image.
      Throws:
      StorageException - When storing the image fails.
    • remove

      public void remove(UUID uuid) throws StorageException
      Remove an image from the S3 bucket.
      Specified by:
      remove in interface StorageProvider
      Parameters:
      uuid - The UUID of the image to remove. You have saved this from the store method.
      Throws:
      StorageException - When the deletion fails.
    • downloadUrlEnabled

      public boolean downloadUrlEnabled()
      Specified by:
      downloadUrlEnabled in interface StorageProvider
    • generateDownloadUrl

      public String generateDownloadUrl(UUID uuid) throws StorageException
      Generate an S3 presigned url that's valid for one day.
      Specified by:
      generateDownloadUrl in interface StorageProvider
      Parameters:
      uuid - The UUID of the image to fetch. You have saved this from the store method.
      Returns:
      The image with the specified UUID.
      Throws:
      StorageException - When the fetching fails.