Created
April 9, 2018 16:08
-
-
Save apple-corps/0ed6d76d9ea5c804e5a7163c993cad98 to your computer and use it in GitHub Desktop.
AWS SDK Java 2 Scala getObjectFile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import software.amazon.awssdk.core.pagination.SdkIterable | |
import software.amazon.awssdk.core.regions.Region | |
import software.amazon.awssdk.services.s3.S3Client | |
import software.amazon.awssdk.services.s3.model.{GetObjectRequest, GetObjectResponse, ListObjectsV2Request, S3Object} | |
import software.amazon.awssdk.services.s3.paginators.ListObjectsV2Iterable | |
import software.amazon.awssdk.core.auth.{AwsCredentialsProvider, EnvironmentVariableCredentialsProvider, InstanceProfileCredentialsProvider, ProfileCredentialsProvider} | |
import software.amazon.awssdk.core.sync.{ResponseInputStream, StreamingResponseHandler} | |
import java.nio.file.Paths | |
import java.io.File | |
def getObjectFile(client: S3Client,bucket: String, key:String) = { | |
client.getObject(GetObjectRequest.builder().bucket(bucket).key(key).build(),StreamingResponseHandler.toFile(Paths.get("/tmp/out")) ) | |
} | |
Error:(30, 12) overloaded method value getObject with alternatives: (x$1: software.amazon.awssdk.services.s3.model.GetObjectRequest,x$2: java.nio.file.Path)software.amazon.awssdk.services.s3.model.GetObjectResponse <and> [ReturnT](x$1: software.amazon.awssdk.services.s3.model.GetObjectRequest, x$2: software.amazon.awssdk.core.sync.StreamingResponseHandler[software.amazon.awssdk.services.s3.model.GetObjectResponse,ReturnT])ReturnT cannot be applied to (software.amazon.awssdk.services.s3.model.GetObjectRequest, software.amazon.awssdk.core.sync.StreamingResponseHandler[Nothing,Nothing]) client.getObject(GetObjectRequest.builder().bucket(bucket).key(key).build(),StreamingResponseHandler.toFile(Paths.get("/tmp/out")) ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def getObjectFile[GetObjectResponse](client: S3Client,bucket: String, key:String, path:String = "/tmp/file") = {
client.getObject(GetObjectRequest.builder().bucket(bucket).key(key).build(),getFileResponseHandler(path))
}
def getFileResponseHandler(path: String): StreamingResponseHandler[GetObjectResponse,GetObjectResponse] =
StreamingResponseHandler.toFile(Paths.get(path))
Solution via aws/aws-sdk-java-v2#94