2017-09-09 60 views

答えて

1

これは、サンプルコードon this pageの直接コピー(IntelliJで変換)です。ここで

val s3client = AmazonS3Client(ProfileCredentialsProvider()) 

val expiration = java.util.Date() 
var msec = expiration.time 
msec += (1000 * 60 * 60).toLong() // 1 hour. 
expiration.time = msec 

val generatePresignedUrlRequest = GeneratePresignedUrlRequest(bucketName, objectKey) 
generatePresignedUrlRequest.setMethod(HttpMethod.GET) // Default. 
generatePresignedUrlRequest.setExpiration(expiration) 

val s = s3client.generatePresignedUrl(generatePresignedUrlRequest) 

はもう少し慣用Kotlinと有効期限の計算のためのJava 8のLocalDateTimeを使用しているのと同じコードです:IntelliJので

val expiration = LocalDateTime.now().plusHours(1) 
val generatePresignedUrlRequest = GeneratePresignedUrlRequest(bucketName, objectKey).apply { 
    method = HttpMethod.GET 
    expiration = Date.from(expiration.atZone(ZoneId.systemDefault()).toInstant()) 
} 
val s3client = AmazonS3Client(ProfileCredentialsProvider()) 
val s = s3client.generatePresignedUrl(generatePresignedUrlRequest) 
関連する問題