Updating Static Files Serviced by SparkJava

I am doing a project using Spark Java. On the server side, some images are created, and I want them to be available on the client. Since I have a directory of static content, after creating the image on the server side, I put it in this directory. However, this file is not available unless I restart the server. I suppose there should be a way to update the static directory file for Spark Java at run time so that requests for executable images at run time can be executed. Right?

Thanks!

+5
source share
2 answers

I solved it by encoding png as Base 64 and sending it as a response to the client.

+2
source

The documentation says:

If you use staticFiles.location(...) , which means that you save your static files in the classpath, the static resources are copied to the destination folder when you create your application. This means that you need to create / create your own project in order to update static files. A workaround for this is to tell Spark to read static files from the absolute path to the src directory.

Therefore use staticFiles.externalLocation() .

+3
source

All Articles