【发布时间】:2022-12-01 00:00:13
【问题描述】:
我知道还有很多类似的问题,this one也不例外
但不幸的是,我无法为我的案例决定区域,我该如何决定正确的区域?
在我的控制台中,我使用的是EU (Frankfurt) eu-central-1,也在终端中这样写:
heroku config:set region="eu-central-1"
据我了解,我的不适合。
这也是我的 AWS 课程:
class AmazonFileStorage : FileStorage {
private val client: S3Client
private val bucketName: String = System.getenv("bucketName")
init {
val region = System.getenv("region")
val accessKey = System.getenv("accessKey")
val secretKey = System.getenv("secretKey")
val credentials = AwsBasicCredentials.create(accessKey, secretKey)
val awsRegion = Region.of(region)
client = S3Client.builder()
.credentialsProvider(StaticCredentialsProvider.create(credentials))
.region(awsRegion)
.build() as S3Client
}
override suspend fun save(file: File): String =
withContext(Dispatchers.IO) {
client.putObject(
PutObjectRequest.builder().bucket(bucketName).key(file.name).acl(ObjectCannedACL.PUBLIC_READ).build(),
RequestBody.fromFile(file)
)
val request = GetUrlRequest.builder().bucket(bucketName).key(file.name).build()
client.utilities().getUrl(request).toExternalForm()
}
}
【问题讨论】:
标签: amazon-web-services kotlin amazon-s3 heroku