[英]How can I read an Excel file (xlsx) from my s3 bucket with Kotlin/Java?
This question is similar than others made but for different languages这个问题与其他问题相似,但针对不同的语言
Python: How to read and load an excel file from AWS S3? Python:如何从 AWS S3 读取和加载 excel 文件?
I am, unfortunately, not able to replicate this, I think the s3 client might be different.不幸的是,我无法复制这一点,我认为 s3 客户端可能会有所不同。
At the moment I am able to connect to read from my s3 bucket, did the following:目前我能够连接到从我的 s3 存储桶中读取,执行以下操作:
val payload = s3.getObject("my-bucket', "my-file.xlsx")
This is returning an object of type S3Object
.这将返回 S3Object 类型的
S3Object
。
As mentioned in other posts for python I should do正如 python 的其他帖子中提到的那样,我应该这样做
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.从有效负载我可以看到我有像
objectContent
这样的方法,但似乎仍然不起作用。
Any idea how to do it?知道怎么做吗?
I am using the AWS SDK 1.11我正在使用 AWS SDK 1.11
You can get InputStream from S3Object, and then write it to a string for example:您可以从 S3Object 获取 InputStream,然后将其写入字符串,例如:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.