Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh static files served by SparkJava

I'm doing a project using Spark Java. On the server side, some images are created and I want them to be available in the client. Since I have a static content directory, after creating the image on the server side, I place it in that directory. However, this file is not available unless I reboot the server. I guess there must be a way to refresh the static directory file for Spark Java on runtime so that requests of on-runtime created images can be fulfilled. Right?

Thanks!

like image 729
jevora Avatar asked Aug 24 '15 11:08

jevora


2 Answers

The documentation says:

If you use staticFiles.location(...), meaning you keep your static files in the classpath, static resources are copied to a target folder when you build your application. This means you have to make/build your project in order to refresh static files. A workaround for this is to tell Spark to read static files from the absolute path to the src-directory.

So use staticFiles.externalLocation() instead.

like image 175
Eduard Wirch Avatar answered Sep 27 '22 22:09

Eduard Wirch


I've solved it by encoding the png as Base 64 and send it as response to the client.

like image 24
jevora Avatar answered Sep 27 '22 20:09

jevora