是否有任何示例工作代码用于在Kotlin中创建S3的预签名URL?我可以从Java示例中调整它吗?
答案 0 :(得分:1)
这是示例代码on this page的直接副本(由IntelliJ转换)。
void addPolygonsToMap()
{
overlayList = new List<IMKOverlay>();
for (int i = 0; i < polygons.Count; i++)
{
CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[polygons[i].Count];
int index=0;
foreach (var position in polygons[i])
{
coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
index++;
}
var blockOverlay = MKPolygon.FromCoordinates(coords);
overlayList.Add(blockOverlay);
}
IMKOverlay[] imko = overlayList.ToArray();
nativeMap.AddOverlays(imko);
}
这是相同的代码,它更像是一个惯用的Kotlin,并使用Java 8 LocalDateTime来计算到期日期:
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)