Inside a grails application, I need to upload a file under web-app/js, add a prefix, and put it in S3. I'm having trouble figuring out how to read the js file in a way that will work in development (/web-app/js) and production (/js). I'm doing this from inside a domain object.
+1
A:
In your controllers, you can call :
def jsFolder = grailsAttributes.getApplicationContext().getResource("js/").getFile()
and then proceed with jsFolder
.
To determine the base directory of a running Grails application, use
String dir = applicationContent.getResource("/").getFile()
Getting the js path from a service is a little bit tricky:
You need to implement the ApplicationContextAware
interface like this :
class MyService implements ApplicationContextAware {
ApplicationContext applicationContext
However, calling this code from a domain class is not a good idea (see this thread for some explanations) and I am not even sure if it's possible except from getting paths from manual configurations
Hope it helps.
fabien7474
2010-04-04 13:50:05
Thanks, Fabien, worked like a champ.
Steve Brewer
2010-04-04 19:28:27