web-dev-qa-db-ja.com

Play Framework2.0でファイルをダウンロードする方法

Play Framework 2.0.3を使用して、ユーザーがダウンロードできるExcelファイルを配信するアプリケーションを作成しています。

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

しかし、response()?tksから出力ストリームを取得する方法

17
ma nicolas

Playのアクションはファイルを返すことができます:

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

これが結果のAPIです

40
biesior

静的ファイルのダウンロードオプションの提供は、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");

他にも利用可能なパラメータがあります

InternetExplorerの場合-必ずコンテンツの配置を設定してください

6
AJ.P

ファイルの提供単純なコンテンツのコンテンツ全体をメモリにロードすることに問題がない場合、大きなデータセットはどうでしょうか。大きなファイルをWebクライアントに送り返したいとしましょう。

続きを読む: http://www.playframework.com/documentation/2.0.x/JavaStream

0
teeyo