Reputation: 13519
I'm developing a CMS and I'd like users to be able to upload their own images, CSS files and the like. For the safety of the resources, I do not want to store the uploaded files within the application structure / deployed WAR.
What is the easiest way to serve content in grails, from a controller from a non-grails location?
Upvotes: 3
Views: 2317
Reputation: 11
I would add a context alias pointing to a remote filesystem folder as explained by cdavis226 in his post:
This solution works if you're using the Grails default Tomcat server.
Upvotes: 1
Reputation: 13519
After much research and questioning, I decided to package the static resources (such as images) in the database. The advantages of this are:
The disadvantages are:
I decided to go with the solution, even though there are these disadvantages. This is how I dealt with them:
I'm using Smart Browser Caching by making use of etags (documentation) and using EHCache (documentation) to cache the images server side. As soon as a new image is uploaded, the e-tag is changed, and the cache is cleared, forcing the browser to download a fresh copy.
So far, the loss of performance from the MySQL database has been un-noticable, and performance is lightning fast.
Upvotes: 1
Reputation: 919
Serving static content via appropriate tools is the correct way, all the web servers offer possibility to achieve this. If you want to implement managing of this content in your Grails application, make the destination of the static content configurable in Config.groovy and that's all.
Do not implement the loading of the content from file system via controller, you are reinventing the wheel ;-) And also the web server are much more performant ;-)
Upvotes: 1