我的应用程序中有一个pdf下载链接,它在所有桌面设备上都能正常工作,但我不能让它在android上工作。
my controller结果如下:
Ok(outputStream.toByteArray)
.withHeaders("Content-Disposition" -> s"""attachment; filename="$ticketId.PDF"""",
"Connection" -> "Keep-Alive",
"Content-Type" -> "application/octet-stream")
只需在Ok
上使用sendFile
函数将文件发送到客户端浏览器。sendFile
通过读取文件扩展名自动将响应内容类型设置为正确类型。因此,它非常用户友好且无bug。
def file = Action {
Ok.sendFile(new File(s"${sys.props("user.home")}/Desktop/something.pdf"), inline = true)
}