2

This question is similar than others made but for different languages

Python: How to read and load an excel file from AWS S3?

I am, unfortunately, not able to replicate this, I think the s3 client might be different.

At the moment I am able to connect to read from my s3 bucket, did the following:

val payload = s3.getObject("my-bucket', "my-file.xlsx")

This is returning an object of type S3Object.

As mentioned in other posts for python I should do

 val binary = payload['Body'].read()

but this is not available for me.

From payload I can see I have methods like objectContent but still doesn't seem to work.

Any idea how to do it?

I am using the AWS SDK 1.11

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
jpganz18
  • 5,508
  • 17
  • 66
  • 115

1 Answers1

0

You can get InputStream from S3Object, and then write it to a string for example:

 S3ObjectInputStream s3ObjectInputStream = s3Client.getObject(new GetObjectRequest(youS3Bucket, youFileName)).getObjectContent();
String result = new BufferedReader(new InputStreamReader(s3ObjectInputStream))
.lines()
.parallel()
.collect(Collectors.joining(System.lineSeparator()));

or to a file:

Files.copy(s3ObjectInputStream, Paths.get("myFile.xlsx"), StandardCopyOption.REPLACE_EXISTING);
Valeriy K.
  • 2,616
  • 1
  • 30
  • 53