공부
[kotlin][AWS] S3Util (get & put)
승가비
2022. 10. 5. 18:09
728x90
import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.services.s3.AmazonS3
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.s3.model.PutObjectRequest
import com.amazonaws.services.s3.model.S3Object
import se.ohou.ads.batch.model.S3
object S3Util {
private fun client(
accessKey: String,
secretKey: String,
region: String
): AmazonS3 {
return AmazonS3ClientBuilder.standard().withCredentials(
AWSStaticCredentialsProvider(
BasicAWSCredentials(accessKey, secretKey)
)
).withRegion(region).build()
}
fun get(s3: S3): S3Object {
with(s3) {
return client(accessKey, secretKey, region)
.getObject(bucketName, key)
}
}
fun put(
s3: S3,
obj: S3Object
) {
with(s3) {
client(accessKey, secretKey, region)
.putObject(
PutObjectRequest(
bucketName,
key,
obj.objectContent,
obj.objectMetadata
)
)
}
}
}
https://peterica.tistory.com/112
[AWS]Spring에서 S3 파일 업로드,다운로드, 삭제, 이름변경 방법
S3의 파일 업로드, 다운로드, 삭제, 이름변경 방법에 대해서 정리하였습니다. gradle // aws s3 implementation 'com.amazonaws:aws-java-sdk-s3:1.11.475' implementation 'com.amazonaws:aws-java-sdk-secretsm..
peterica.tistory.com
728x90