DanC
DanC

Reputation: 8805

Relative URL to server path conversion - Grails

In a custom tag, I am receiving as a parameter the url of a file, which I need to open.

I have this

/content/data.html

which is the output from

${createLinkTo(dir:'content',file:'data.html')}:

and I need the 'server path':

C:\mygrailsapp\web-app\content\data.html

Upvotes: 2

Views: 849

Answers (1)

Burt Beckwith
Burt Beckwith

Reputation: 75671

You can use the Spring application context to find resources. This works if it's under web-app folder:

class FooController {

   def grailsApplication

   def myAction = {
      String path = params.path // '/content/data.html'
      def resource = grailsApplication.mainContext.getResource(path)
      String text = resource.inputStream.text
      ...
   }
}

Upvotes: 3

Related Questions