scala - Play Framework - only getting file content from Ok.sendFile(file) -


my users need download file when hitting controller in play application. thought trick:

def downloadfile = action {   ok.sendfile(new file("example.zip")) } 

but seems give actual content of file instead of downloading file. tell me i'm doing wrong?

thanks

try instead:

def index = action {   ok.sendfile(     content = new java.io.file("/tmp/filetoserve.pdf"),     filename = _ => "termsofservice.pdf"   ) } 

its documentation itself.

now don’t have specify file name since web browser not try download it, display file content in web browser window. useful content types supported natively web browser, such text, html or images.

see this: https://www.playframework.com/documentation/2.0/scalastream


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -