2017-07-04 4 views
0

私はS3アップロードを処理するためにAlpakkaを使い、Akka Steamsでダウンロードしたいと思っていました。しかし、私は、S3ClientがAkka Httpルートで作成したSourceを使用することに固執しました。私が取得エラーメッセージは次のとおりです。Akka-Httpでソース[ByteString、_]を完成

[error] found : akka.stream.scaladsl.Source[akka.util.ByteString,_$1] where type _$1 
[error] required: akka.http.scaladsl.marshalling.ToResponseMarshallable 
[error]  complete(source) 

私は暗黙のインポートが欠落ように、それはいくつかの迷惑な些細な事であると仮定し、私は、私が行方不明です何を正確に特定することができませんでした。

私は、問題を説明するために、いくつかの最低限の例を作成しました:

import akka.actor.ActorSystem 
import akka.http.scaladsl.Http 
import akka.http.scaladsl.server.Directives._ 
import akka.stream.ActorMaterializer 
import akka.stream.scaladsl.Source 
import akka.util.ByteString 

import scala.concurrent.ExecutionContext 

class Test { 

    implicit val actorSystem: ActorSystem = ActorSystem() 
    implicit val materializer: ActorMaterializer = ActorMaterializer() 
    implicit val executionContext: ExecutionContext = actorSystem.dispatcher 

    val route = (path("test") & get) { 
    def source: Source[ByteString, _] = ??? // just assume that I am able to get that value 
    complete(source) // here error happens 
    } 

    Http().bindAndHandle(route, "localhost", 8000) 
} 

あなたはいくつかの提案を持っていますか、私は何を試すことができますか?私は、あなたがソースからHttpEntityを作成し、それをコンテンツタイプを与える必要が

libraryDependencies += "com.typesafe.akka"%% "akka-http" % "10.0.5" 

答えて

4

を使用しています。

complete(HttpEntity(ContentTypes.`application/json`, source)) 
+0

具体的には、「HttpEntity.Default」です。 "これは既知の長さを持ち、ソース[ByteString]"としてデータを提示します。 –

+1

ありがとう!私はhttp://doc.akka.io/docs/akka-http/10.0.9/scala/http/routing-dsl/source-streaming-support.htmlの第2段落に混乱しました。私(ミス)は、私が紛失している暗黙的な変換があることを理解しました。 –

+0

私は参照してください。さらに暗黙のことは、カスタムクラスを直接ストリームに変換し、そのクラスをJSONに変換する場合にのみ必要です。 –

関連する問題