Package com.example.blogs.app.storage
Class S3BucketServiceImpl
java.lang.Object
com.example.blogs.app.storage.S3BucketServiceImpl
- All Implemented Interfaces:
S3BucketService
Implementation of S3 bucket operations using AWS SDK for file uploads.
-
Constructor Summary
ConstructorsConstructorDescriptionS3BucketServiceImpl(software.amazon.awssdk.services.s3.S3Client s3Client, String bucketName, S3KeyGenerator s3KeyGenerator) Constructs S3 bucket service with configured client and bucket name. -
Method Summary
Modifier and TypeMethodDescriptionvoidDeletes a file from the S3 bucket by constructing its key and sending a delete request.voidUploads a file to the S3 bucket with specified metadata.
-
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 clientbucketName- the name of the S3 bucket to uses3KeyGenerator- 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:
uploadin interfaceS3BucketService- Parameters:
filePath- the storage path within the bucketfileName- the file name without extensionextension- the file extension including the dot (e.g., ".png")contentType- the MIME type of the filefileData- the file content as byte array- Throws:
FailedToStoreFileException- if the S3 upload operation fails
-
delete
Deletes a file from the S3 bucket by constructing its key and sending a delete request.- Specified by:
deletein interfaceS3BucketService- Parameters:
filePath- the storage path within the bucketfileName- the file name without extensionextension- the file extension including the dot (e.g., ".png")- Throws:
FailedToDeleteFileException- if the S3 delete operation fails
-