如何使用Play Framework 2.0下载文件 [英] How to download a file with Play Framework 2.0

查看:135
本文介绍了如何使用Play Framework 2.0下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Play Framework 2.0.3创建一个应用程序,该应用程序提供应该可由用户下载的Excel文件。

  response()。setContentType(application / x-download); 
response()。setHeader(Content-disposition,attachment; filename = tradeLogTest.xlsx);

但是,如何从获取输出流响应()?tks

解决方案

Play的动作可以返回一个文件:



< 。pre> 响应()的setContentType( 应用程序/ x-下载);
response()。setHeader(Content-disposition,attachment; filename = tradeLogTest.xlsx);
返回ok(新文件(/ absolute / path / to / tradeLogTest.xlsx));

这是结果的API


I'm using Play Framework 2.0.3 to create an application which delivers Excel files that should be downloadable by the user.

 response().setContentType("application/x-download");  
 response().setHeader("Content-disposition","attachment; filename=tradeLogTest.xlsx");  

but,how to get the outputstream from response()?tks

解决方案

Play's action can return a File:

response().setContentType("application/x-download");  
response().setHeader("Content-disposition","attachment; filename=tradeLogTest.xlsx"); 
return ok(new File("/absolute/path/to/tradeLogTest.xlsx"));

Here's an API for Results

这篇关于如何使用Play Framework 2.0下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆