How to download a file with Play Framework 2.0

前端 未结 3 1553
情深已故
情深已故 2021-02-02 13:59

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(\"applic         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-02 14:14

    Providing download option for static files can be done in Play as:

    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

提交回复
热议问题