0

I am working with Grails 2.4.2. I am saving images to a directory named gameImage under web-app folder. It's working perfectly in development mode. But when I run the war on localhost in the xampp server then in the view image is not showing but saving in the directory. Here are my attempts below ::

In my config file >>>

gameImage.location = "web-app/apps/gameImage/"

In my controller where saving image >>>

String fileName = grailsApplication.config.gameImage.location.toString() + distGameInstance.packageName + '_' + newGameImage.getOriginalFilename()
new File( grailsApplication.config.gameImage.location.toString() ).mkdirs()
newGameImage.transferTo( new File( fileName) )

In my view where I want to show the image >>>

<g:each in="${distributedGameListInstance}" status="i" var="androidDistGameInstance">
   <div class="col-lg-3 col-md-4 col-xs-6 thumb" >
      <a class="thumbnail" href="#">
          <g:img uri="${resource(dir: "apps/gameImage", file: "${androidDistGameInstance.imageName}")}" style="height: 120px;width: 120px;" />
      </a>
   </div>
</g:each>
Sumon Bappi
  • 1,937
  • 8
  • 38
  • 82
  • and you have added apps folder to the rule as well grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*'] – V H May 24 '15 at 00:41
  • @vahid thanks for your reply but don't get it. Can you explain a little bit more please – Sumon Bappi May 24 '15 at 04:05
  • add this line in config file but no result – Sumon Bappi May 24 '15 at 04:43
  • and it included your apps folder too ? grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*', '/apps/*'] also take a look here try debugging it http://stackoverflow.com/questions/18741877/resource-not-found-error-and-what-about-resources-plugin – V H May 24 '15 at 11:44

1 Answers1

0

There is no need to config about folder in config.groovy. just follow the below code. at least worked for me :::

    def gameImage = request.getFile('appImage')
String imagePath = "${request.getRealPath('/')}/apps/gameImage/"
new File( imagePath ).mkdirs()
gameImage.transferTo( new File( imagePath + File.separatorChar + gameImageName) )
Sumon Bappi
  • 1,937
  • 8
  • 38
  • 82