首页 > 解决方案 > 使用 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。有人可以指导我在哪里出错吗?

标签: scalaamazon-s3akka-streamalpakka

解决方案


  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 {

}

推荐阅读