简体   繁体   中英

Akka HTTP Client EntityStreamSizeException

I'm trying to send a get request to my localhost using Akka HTTP and I get the following exception:

EntityStreamSizeException: actual entity size (Some(10166731700)) exceeded content length limit (8388608 bytes)! You can configure this by setting akka.http.[server|client].parsing.max-content-length or calling HttpEntity.withSizeLimit before materializing the dataBytes stream.)

Basically, the file on my localhost which I'm trying to request is very large.

I tried to solve it by using withoutSizeLimit , but it's not working:

val request = Get("http://localhost:8080/oa-ok.ntriples")
val limitedRequest = request.withEntity(request.entity.withoutSizeLimit())
val responseFuture = Http().singleRequest(limitedRequest)

I also tried to use withSizeLimit and it didn't help. Any ideas?

Use withoutSizeLimit on the response entity, not the request entity. For example:

val responseFuture: Future[HttpResponse] =
  Http().singleRequest(HttpRequest(uri = "http://localhost:8080/oa-ok.ntriples"))

val responseSource: Source[ByteString, NotUsed] =
  Source.fromFuture(responseFuture)
    .flatMapConcat(_entity.withoutSizeLimit.dataBytes)

responseSource is an Akka Streams Source of the response entity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM