我想流式传输来自远程服务器的大量响应。
例如-我使用以下代码从维基媒体流式传输图像。 预期它将以小块的形式将图像流式传输回客户端。但是,它会加载整个图像,然后将其发送给客户端。
Action.async { implicit request =>
val futureResponse = ws.url(
"https://upload.wikimedia.org/wikipedia/commons/c/c7/%2271%22_on_St._Patrick%27s_Day._Washington%2C_D.C.%2C_March_17._" +
"Justice_Pierce_Butler%2C_71_years_old_today_celebrates_his_birthday_by_taking_his_morning_walk%2C_snapped_while_leaving_his_home_on_19" +
"th_LCCN2016871374.tif")
.withMethod("GET")
.stream()
futureResponse.map {
f =>
Ok.chunked(f.bodyAsSource)
}
}
我复制了 https://www.playframework.com/documentation/2.8.x/ScalaWS#Processing-large-responses 中给出的整个代码,但它也不起作用
Play版本是2.8.19.