hkievet
hkievet

Reputation: 169

Where do I store Excel Template resources for a Grails Application

I'm trying to access an Excel Template by a string URL from a controller.

  1. What directory should I place my Excel Templates in my Grails project? (i.e., WEB-INF, grails-app/assets, etc.,)
  2. What will the URI be for it after packaging it as a .war and putting it in the Tomcat 7 container??

Edit

I'm using

def wb = new WebXlsxExporter("/path/to/excel/template")

Which requires the string URL of where the file is stored.

Upvotes: 0

Views: 261

Answers (2)

hkievet
hkievet

Reputation: 169

So I found the answer... ExcelTemplates folder is in the web-app folder. To get the URL without receiving a file not found error I used

request.getSession().getServletContext().getRealPath(.....)
---------
//Which looks like this when implemented

def wb = new WebXlsxExporter(request.getSession().getServletContext().getRealPath("/ExcelTemplates/testTemplate.xlsx"))

When compiled into a war and placed in the Tomcat 7 /webapp directory, everything works great!

Upvotes: 2

Joe
Joe

Reputation: 1219

You can put them under the web-app directory. Then you can get them using the following code as an InputStream.

private byte[] getLogoBytes() {
    InputStream logo = servletContext.getResourceAsStream('/images/logo.png')
    return logo.getBytes()
}

Upvotes: 1

Related Questions