我正在尝试使用 akka-streams 和 akka-http 以及 alpakka 库将文件下载/上传到 Amazon S3。我看到两个可能相关的问题......
- 我只能下载很小的文件,最大的一个8kb。
我无法上传更大的文件。它失败并显示消息
处理请求时出错:“子流源未在 5000 毫秒内实现”。完成 500 内部服务器错误响应。要更改默认异常处理行为,请提供自定义 ExceptionHandler。akka.stream.impl.SubscriptionTimeoutException:子流源未在 5000 毫秒内实现
这是我的路线
pathEnd {
post {
fileUpload("attachment") {
case (metadata, byteSource) => {
val writeResult: Future[MultipartUploadResult] = byteSource.runWith(client.multipartUpload("bucketname", key))
onSuccess(writeResult) { result =>
complete(result.location.toString())
}
}
}
}
} ~
path("key" / Segment) {
(sourceSystem, sourceTable, sourceId) =>
get {
val result: Future[ByteString] =
client.download("bucketname", key).runWith(Sink.head)
onSuccess(result) {
complete(_)
}
}
}
尝试下载 100KB 的文件最终会获取文件的截断版本,通常大小约为 16-25Kb 任何帮助表示赞赏
编辑:对于下载问题,我接受了 Stefano 的建议并得到了
[error] found : akka.stream.scaladsl.Source[akka.util.ByteString,akka.NotUsed]
[error] required: akka.http.scaladsl.marshalling.ToResponseMarshallable
这使它工作
complete(HttpEntity(ContentTypes.`application/octet-stream`, client.download("bucketname", key).runWith(Sink.head)))