[英]How to download a file with Play Framework 2.0
I'm using Play Framework 2.0.3 to create an application which delivers Excel files that should be downloadable by the user. 我正在使用Play Framework 2.0.3创建一个应用程序,该应用程序提供应该可由用户下载的Excel文件。
response().setContentType("application/x-download");
response().setHeader("Content-disposition","attachment; filename=tradeLogTest.xlsx");
but,how to get the outputstream from response()
?tks 但是,如何从response()
?tks获取输出流
Play's action can return a File: Play的动作可以返回一个文件:
response().setContentType("application/x-download");
response().setHeader("Content-disposition","attachment; filename=tradeLogTest.xlsx");
return ok(new File("/absolute/path/to/tradeLogTest.xlsx"));
Providing download option for static files can be done in Play as: 提供静态文件的下载选项可以在Play中完成:
Ok.sendFile(new File("path to file/abc.csv"), inline=true).withHeaders(CACHE_CONTROL->"max-age=3600",CONTENT_DISPOSITION->"attachment; filename=abc.csv", CONTENT_TYPE->"application/x-download");
There are other parameters that are also available 还有其他参数可用
For Internet Explorer - make sure you set the Content Disposition 对于Internet Explorer - 请确保设置“内容处理”
Serving files If it's not a problem to load the whole content into memory for simple content what about a large data set? 服务文件如果将整个内容加载到内存中以获取简单内容,那么大数据集又是什么问题? Let's say we want to send back a large file to the web client. 假设我们想要将大文件发送回Web客户端。
read more at : http://www.playframework.com/documentation/2.0.x/JavaStream 欲了解更多信息,请访问: http : //www.playframework.com/documentation/2.0.x/JavaStream
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.