Reputation: 3155
I am currently developing a web app using play framework 2. I have created a folder "files" under /public directory. All the resources under that directory were accessible when I start the server using "play run".
After deploy to the server. I started the server by running "play start" and found the resources under "files" cannot be found anymore.
I am wondering what is the cause of the inconsistency between "play start" and "play run"
UPDATE:After a few trial. I found that it's the newly uploaded resource cannot be shown. The scenario is the following:
1. play start --> server starts.
2. use application to upload a few images to the server.
3. try to display the uploaded image --> nothing is shown. browser shows the resource is not accessible.
4. kill the server process with task manager.
5. rm RUNNING_PID
6. run play start again
7. Try to display the uploaded image --> now the images are showing.
So, looks like a "hot update" issue with "play start" Is there any configuration I can do to let the server pick up the change? Thanks.
Upvotes: 3
Views: 760
Reputation: 3155
Based on @Joerg Viola 's answer. I decided to implement my own action to serve static resource. Turns out it's extremely easy. From this link
, I learnt to implement a file server in one line.
Upvotes: 2
Reputation: 246
Where exactly did you store the image?
At compile time, the static assets are copied from /public
to /target/scala-2.9.1/classes/public
. This directory is part of the class path and the assets are served from there. So, if you store files there at runtime, they should be found.
Side note: It is probably not a sustainable solution since images loaded up by your users are removed during the next build. Maybe you should consider using a symbolic link outside your app installation (attention! security issue!) or store the assets somewhere else, the database or S3 always being good alternatives.
Upvotes: 6