[2.5.3-Java] Strange problem downloading file

64 views
Skip to first unread message

Enrico Morelli

unread,
May 23, 2016, 9:23:24 AM5/23/16
to play-framework
I've a very strange problem. I use a RHEL 6 32bit workstation to develop Play! application with Oracle JDK 1.8.71. When all works fine I put everything on a server RHEL 6 64bit with the same JDK version and I create the stage to use in production.

Now I've a simple app that creates a pdf file and permits to an user to download it using the following method:

@Security.Authenticated(Secured.class)
@With(Perms.class)
public Result download(String n) {
   
String filename = "Ricevuta" + n + ".pdf";
   
System.out.println("Download: " + filename);
   
response().setContentType("application/x-download");
   
response().setHeader("Content-disposition","attachment; filename=" + filename);
   
return ok(new File("public/tmp/" + filename));
}

Clicking on a template icon:

<acronym title="Download Ricevuta">
   
<a href="@routes.Receipt.download(value(0))"><span class="glyphicon glyphicon-download" ></span></a>
</acronym>

When I click on the icon on my machine all works fine, the browser open the download window. On the server nothing happens and no error occurs.

The file is really created in public/tmp, If I put the server running in development mode (via activator run), all works fine.
If I copy the file in target/universal/stage/public/tmp/ all works fine also using the stage.
If I try to create the pdf directly under target/universal/stage/public/tmp/ the file in empty.

So, where I've to create the PDF to be able to download it in both mode?

Greg Methvin

unread,
May 23, 2016, 1:44:28 PM5/23/16
to play-framework
Hi Enrico,

It looks like you're trying to upload a file to a directory on the classpath. Normally this shouldn't actually work, since your application's classpath is immutable once started (and there are good reasons for that). It probably seems to "work" in dev mode because Play is detecting a change and reloading the app.

Instead, you probably want to define a directory in configuration where your uploaded files are stored, and upload to that physical directory.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/d4093f3a-fbc7-4635-9e05-30cc2ebb0ed4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Greg Methvin
Senior Software Engineer

Enrico Morelli

unread,
May 24, 2016, 11:20:49 AM5/24/16
to play-framework
Thanks, seems to be working.


On Monday, May 23, 2016 at 7:44:28 PM UTC+2, Greg Methvin wrote:
Hi Enrico,

It looks like you're trying to upload a file to a directory on the classpath. Normally this shouldn't actually work, since your application's classpath is immutable once started (and there are good reasons for that). It probably seems to "work" in dev mode because Play is detecting a change and reloading the app.

Instead, you probably want to define a directory in configuration where your uploaded files are stored, and upload to that physical directory.
Reply all
Reply to author
Forward
0 new messages