I am a new to working with kotlin and the AWS kotlin SDK. Our application receives via AWS SQS an URL form a AWS S3 Bucket pointing to a file. We do have to download the file in our application for further processing. We found the following example code link which is cool.
val request = GetObjectRequest {
key = keyName
bucket = bucketName
}
S3Client { region = "us-east-1" }.use { s3 ->
s3.getObject(request) { resp ->
val myFile = File(path)
resp.body?.writeToFile(myFile)
println("Successfully read $keyName from $bucketName")
}
}
However we don't know how to transform a S3 Bucket URL into a GetOjectRequest, for java we fond the following code on "Stackoverflow" link :-)
URI fileToBeDownloaded = new URI(" https://s3.amazonaws.com/account-update/input.csv");
AmazonS3URI s3URI = new AmazonS3URI(fileToBeDownloaded);
S3Object s3Object = s3Client.getObject(s3URI.getBucket(), s3URI.getKey());
So how to download a S3 Bucket file using the AWS kotlin SDK and and how to convert a URL into a bucketName and a keyName in the same way as in the Java example above.