Need to steps for exporting(downloading) the file(.txt or .cvs) with data from play 2 application

1,365 views
Skip to first unread message

gsp

unread,
May 11, 2012, 1:51:34 AM5/11/12
to play-fr...@googlegroups.com
Hi,

This is siva, I am newly learning play 2 framework, I am trying to export the data in the form of file(.txt or .csv).



--
Thanks&Regards,
Sivaprasad.gudluri,
+91-7418674647.

Mathias Clerc

unread,
May 11, 2012, 2:53:42 AM5/11/12
to play-fr...@googlegroups.com
In your controller do :
File myFile = ...
return ok(myFile);

You can also pass an inputStream as parameter to ok() if it is more
convenient for you

2012/5/11 gsp <gsp...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.

gsp

unread,
May 11, 2012, 6:30:28 AM5/11/12
to play-fr...@googlegroups.com
Mathias Clerc ,

Thank you for response.

I am trying download file(.txt or .csv)  from http responce, please see screen shot for my exact requirement.
If I click on export button it will ask to save or open the file, If we choose OK button it will save downloads.

Inline image 2
Please give steps for this scenario.
--
Thanks&Regards,
Sivaprasad.gudluri,
+91-7418674647.

image.png

Kevin Bosman

unread,
May 11, 2012, 7:00:42 AM5/11/12
to play-fr...@googlegroups.com
> Please give steps for this scenario.

To force a file download action within the browser, your response
needs the Content-Disposition header, and provide a mime type.

In a Scala controller, you can use Ok.sendFile() to send the file with
the correct headers

In Java, you need to set the headers yourself, like so:

File myFile = ...
response().setHeader("Content-Disposition", "attachment; filename=\""
+ filename + "\"")
return ok(myFile).as("text/csv");

gsp

unread,
May 14, 2012, 1:36:33 AM5/14/12
to play-fr...@googlegroups.com
Mathias Clerc ,

Thank you for response.

Its working fine.
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.




--
Thanks&Regards,
Sivaprasad.gudluri,
+91-7418674647.

Reply all
Reply to author
Forward
0 new messages