Search code examples
grailsintellij-ideagrails3.2.0

Get Application path in grails controller


I'm currently use Intellij idea for grails project.

I want to upload, user profile picture to project directory. e.g. E:\MyProject\userUploads

currently i'm trying to get path using following code

def filePath = request.getSession().getServletContext().getRealPath("/")

But when i print the filePath i get:

C:\Users\Rahul.Mahadik\AppData\Local\Temp\tomcat-docbase.2236924879274963579.8080\

Also i was tried "servletContext.getRealPath("/")" this also to get path of my current directory but getting same path like above

Thanks


Solution

  • Solved my problem by adding following in application.yml

    server.contextPath: /
    

    OR

    If i run app with grails -Dapp.context=/ run-app