Class S3BucketServiceImpl

java.lang.Object
com.example.blogs.app.storage.S3BucketServiceImpl
All Implemented Interfaces:
S3BucketService

@Service public class S3BucketServiceImpl extends Object implements S3BucketService
Implementation of S3 bucket operations using AWS SDK for file uploads.
  • Constructor Details

    • S3BucketServiceImpl

      public S3BucketServiceImpl(software.amazon.awssdk.services.s3.S3Client s3Client, @Value("${aws.s3.bucketName}") String bucketName, S3KeyGenerator s3KeyGenerator)
      Constructs S3 bucket service with configured client and bucket name.
      Parameters:
      s3Client - the configured S3 client
      bucketName - the name of the S3 bucket to use
      s3KeyGenerator - the S3 key generator for constructing object keys
  • Method Details

    • upload

      public void upload(String filePath, String fileName, String extension, String contentType, byte[] fileData)
      Uploads a file to the S3 bucket with specified metadata. Constructs the S3 key from path and filename, then uploads with content type.
      Specified by:
      upload in interface S3BucketService
      Parameters:
      filePath - the storage path within the bucket
      fileName - the file name without extension
      extension - the file extension including the dot (e.g., ".png")
      contentType - the MIME type of the file
      fileData - the file content as byte array
      Throws:
      FailedToStoreFileException - if the S3 upload operation fails
    • delete

      public void delete(String filePath, String fileName, String extension)
      Deletes a file from the S3 bucket by constructing its key and sending a delete request.
      Specified by:
      delete in interface S3BucketService
      Parameters:
      filePath - the storage path within the bucket
      fileName - the file name without extension
      extension - the file extension including the dot (e.g., ".png")
      Throws:
      FailedToDeleteFileException - if the S3 delete operation fails