I have to create (not upload!), store and be able to download the PDF file using Play 2.0 application. How I could do this in Play? I'm thinking of storing file as blob in MySQL DB, but in that case is there an opportunity to create PDF file without using the filesystem? Second question is how to implement the file downloading?
Asked
Active
Viewed 938 times
1 Answers
2
In very general, storing files in database is usually more expensive and has some disadvantages. (check why: Storing Images in DB - Yea or Nay?)
On the other hand it also depends if the files should be protected, or they are some kind of public docs.
There are two solutions to consider:
- if you don't worry about security, you can just create files and save in some folder, than, you can use some http server to serve it and in your DB keep only the paths. This is good idea, especially that usually servers are just created for serving files, so you won't need to reinvent the wheel.
if files are restricted, also store them in the filesystem, anyway in some non-public folder, then you can return a
File
as aResult
of the action only for authenticated/authorized visitors with such simple piece of code (Java)public static Result serveFile(String absouteFilePath){ //some authorization... return ok(new File(absouteFilePath)); }
-
Solved with storing files in the filesystem and their metadata in DB. Thanks! – Jolene Dec 17 '12 at 14:22