scala - 使用 akka-stream-alpakka 从 s3 下载 pdf 文件
问题描述
我正在尝试使用akka-stream-alpakka
连接器从 S3 下载 pdf 文件。我有 s3 路径并尝试在 alpakka s3Client 上使用包装器方法下载 pdf。
def getSource(s3Path: String): Source[ByteString, NotUsed] = {
val (source, _) = s3Client.download(s3Bucket, s3Path)
source
}
从我的主代码中,我调用上述方法并尝试将其转换为文件
val file = new File("certificate.pdf")
val res: Future[IOResult] = getSource(data.s3PdfPath)
.runWith(FileIO.toFile(file))
但是,我没有将其转换为文件,而是使用了一种 IOResult。有人可以指导我在哪里出错吗?
解决方案
def download(bucket: String, bucketKey: String, filePath: String) = {
val (s3Source: Source[ByteString, _], _) = s3Client.download(bucket, bucketKey)
val result = s3Source.toMat(FileIO.toPath(Paths.get(filePath)))(Keep.right)
.run()
result
}
download(s3Bucket, key, newSigFilepath).onComplete {
}
推荐阅读
- sql-server - 将长 java 时间戳转换为 sqlserver 日期
- python - 在python中附加到JSON文件
- attributes - Prestashop 1.7 属性组 - 检查库存并将 css 应用于不可用的组合
- javascript - 围绕另一个图标旋转图标
- angular - 在托管具有差异加载的 Angular 应用程序时,如何确定可以使用 HTTP 2 Server Push 推送哪些文件?
- python - 使用 ctypes 传递引用地址结构
- java - 读取和写入 NFC
- python - 在 Django Admin 中使字段唯一
- python - 自定义网格单元编辑器。ComboBox 小部件的不正确行为
- c++ - 保留() - 空向量上的数据()技巧 - 正确吗?