Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playframework: Strange behavior of "play start" - Caching issue?

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.

like image 846
Wei Ma Avatar asked Jan 26 '26 07:01

Wei Ma


2 Answers

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.

like image 82
Joerg Viola Avatar answered Jan 29 '26 01:01

Joerg Viola


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.

like image 37
Wei Ma Avatar answered Jan 29 '26 01:01

Wei Ma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!