在AWS Java SDK 1.x中,我可以像这样从S3Object
获得S3Client
。
S3Object obj = mS3Client.getObject(pBucket, pKey);
我正在尝试使用AWS Java SDK 2.0复制该功能(并以S3Object
结尾),但是我能得到的最接近的是GetObjectResponse
,而且我找不到任何简单的方法调用来将响应转换为S3Object
。GetObjectResponse response = mS3Client.getObject(
GetObjectRequest.builder()
.bucket(pBucket)
.key(pKey)
.build())
.response();
如何从2.0 S3Object
获取S3Client
或从GetObjectResponse
构建一个ojit_code? 最佳答案
使用ResponseInputStream。希望下面的代码能解决您的问题。
GetObjectRequest request = GetObjectRequest.builder()
.bucket("BucketName")
.key("key")
.build();
ResponseInputStream<GetObjectResponse> s3objectResponse = s3Client
.getObject(request);
BufferedReader reader = new BufferedReader(new InputStreamReader(s3objectResponse));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
关于java - 从AWS Java SDK 2.0中的GetObjectResponse获取S3Object,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54447306/