Package io.jmix.awsfs

Class AwsFileStorage

java.lang.Object
io.jmix.awsfs.AwsFileStorage
All Implemented Interfaces:
FileStorage

@Component("awsfs_FileStorage") public class AwsFileStorage extends Object implements FileStorage
  • Field Details

    • storageName

      protected String storageName
    • properties

      @Autowired protected AwsFileStorageProperties properties
    • accessKey

      protected String accessKey
    • secretAccessKey

      protected String secretAccessKey
    • region

      protected String region
    • bucket

      protected String bucket
    • chunkSize

      protected int chunkSize
    • endpointUrl

      protected String endpointUrl
    • timeSource

      @Autowired protected TimeSource timeSource
    • s3ClientReference

      protected AtomicReference<software.amazon.awssdk.services.s3.S3Client> s3ClientReference
  • Constructor Details

    • AwsFileStorage

      public AwsFileStorage()
    • AwsFileStorage

      public AwsFileStorage(String storageName)
    • AwsFileStorage

      public AwsFileStorage(String storageName, String accessKey, String secretAccessKey, String region, String bucket, int chunkSize, @Nullable String endpointUrl)
      Optional constructor that allows you to override AwsFileStorageProperties.
  • Method Details

    • initS3Client

      @EventListener protected void initS3Client(org.springframework.boot.context.event.ApplicationStartedEvent event)
    • refreshProperties

      protected void refreshProperties()
    • getAwsCredentialsProvider

      protected software.amazon.awssdk.auth.credentials.AwsCredentialsProvider getAwsCredentialsProvider()
    • refreshS3Client

      public void refreshS3Client()
    • getStorageName

      public String getStorageName()
      Description copied from interface: FileStorage
      Returns the name of this storage, which will be saved in FileRefs.

      Each file storage in the application should have a unique name.

      Specified by:
      getStorageName in interface FileStorage
    • createFileKey

      protected String createFileKey(String fileName)
    • createDateDir

      protected String createDateDir()
    • createUuidFilename

      protected String createUuidFilename(String fileName)
    • saveStream

      public FileRef saveStream(String fileName, InputStream inputStream, Map<String,Object> parameters)
      Description copied from interface: FileStorage
      Saves an InputStream contents into the file storage using additional parameters.
      Specified by:
      saveStream in interface FileStorage
      Parameters:
      fileName - file name
      inputStream - input stream, must be closed in the calling code
      parameters - additional parameters that can be used in specific storage implementation (for example, can be converted to FileRef parameters)
      Returns:
      file reference
    • openStream

      public InputStream openStream(FileRef reference)
      Description copied from interface: FileStorage
      Returns an input stream to load a file contents.
      Specified by:
      openStream in interface FileStorage
      Parameters:
      reference - file reference
      Returns:
      input stream, must be closed after use
    • removeFile

      public void removeFile(FileRef reference)
      Description copied from interface: FileStorage
      Removes a file from the file storage.
      Specified by:
      removeFile in interface FileStorage
      Parameters:
      reference - file reference
    • fileExists

      public boolean fileExists(FileRef reference)
      Description copied from interface: FileStorage
      Tests whether the file denoted by this file reference exists.
      Specified by:
      fileExists in interface FileStorage
      Parameters:
      reference - file reference
      Returns:
      true if the file denoted by this file reference exists
    • setAccessKey

      public void setAccessKey(String accessKey)
    • setSecretAccessKey

      public void setSecretAccessKey(String secretAccessKey)
    • setRegion

      public void setRegion(String region)
    • setBucket

      public void setBucket(String bucket)
    • setChunkSize

      public void setChunkSize(int chunkSize)
    • setEndpointUrl

      public void setEndpointUrl(@Nullable String endpointUrl)