简体   繁体   English

如何使用 Kotlin/Java 从我的 s3 存储桶中读取 Excel 文件 (xlsx)?

[英]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.

相关问题 我想从具有Java库Apache Poi的excel .xlsx文件中读取,但是我无法修复错误,代码无法编译 - I want to read from excel .xlsx file with java's library Apache Poi, but I can't fix an error, code does not compile 如何将 AWS S3 存储桶中的 excel 文件放入 Java 中的 MultipartFile - How to get an excel file from AWS S3 bucket into a MultipartFile in Java 如何在java中读取Excel(.xlsx)文件? - How to read Excel (.xlsx) file in java? 如何使用Java读取Spark中的xls和xlsx文件? - how can I read xls and xlsx file in spark with java? 如何从 s3 自动获取 java 中的文件? - How can I automatically get file in java from s3? 使用 Java 从 S3 存储桶和 HTTP PUT 文件读取文件到预签名的 AWS S3 URL 以模拟实际文件上传的方式另一个存储桶 - Read a file using Java from an S3 bucket and HTTP PUT file to presigned AWS S3 URL of another bucket in a way that simulates an actual file upload 如何在AWS S3存储桶中使用Java读取压缩的CSV文件? - How to read a zipped CSV file using Java inside an AWS S3 bucket? 如何从Java读取xlsx文件 - How to read xlsx file from Java 如何用Java读取Excel文件? - How can I read Excel file in Java? 如何使用Java从Amazon S3存储桶中使用其名称下载垂直文件 - how to download a perticular file using it's name from amazon s3 bucket using java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM