public class S3StorageService extends Object implements AutoCloseable
| Constructor and Description |
|---|
S3StorageService(software.amazon.awssdk.regions.Region region)
Creates an S3 client using the default AWS credentials/provider chain.
|
S3StorageService(software.amazon.awssdk.regions.Region region,
String accessKey,
String secretKey)
Creates an S3 client using explicit access key and secret key (e.g.
|
S3StorageService(software.amazon.awssdk.services.s3.S3Client s3Client)
Alternate constructor if you want to inject a pre-configured client (recommended for testing).
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
InputStream |
downloadAsStream(String bucketName,
String key)
Optional helper: download S3 object as InputStream (caller must close it).
|
void |
downloadFile(String bucketName,
String key,
Path destinationPath)
Downloads an S3 object to a local file.
|
boolean |
exists(String bucketName,
String key)
Optional helper: check if an object exists.
|
void |
uploadFile(String bucketName,
String key,
Path localFilePath)
Uploads a local file to S3.
|
public S3StorageService(software.amazon.awssdk.regions.Region region)
public S3StorageService(software.amazon.awssdk.regions.Region region,
String accessKey,
String secretKey)
public S3StorageService(software.amazon.awssdk.services.s3.S3Client s3Client)
public void uploadFile(String bucketName, String key, Path localFilePath)
bucketName - S3 bucket namekey - S3 object key (e.g., "folder/file.txt")localFilePath - path to local filepublic void downloadFile(String bucketName, String key, Path destinationPath)
bucketName - S3 bucket namekey - S3 object keydestinationPath - local destination file pathpublic InputStream downloadAsStream(String bucketName, String key)
public boolean exists(String bucketName, String key)
public void close()
close in interface AutoCloseableCopyright © 2026. All rights reserved.