Search code examples
grailsgroovy

Grails 2.3.11 broken image display


I make a web app that with every new entry by user it creates a folder under grails-app/conf/templates/(user.id)

   def showImage(){
        def baseFolder = 'E:\\untitled1\\grails-app\\conf\\templates'
        def subFolder = baseFolder + '\\' + "${item.id}"
        def imageList1 = new File(subFolder).list()
        println imageList1
        def imageList = Arrays.asList(imageList1)
        println imageList
        [imageList: imageList]}

and here my gsp

<g:each in="${imageList}" status="i" var="image">

<img src="${createLinkTo(dir: 'E:\\untitled1\\grails- app\\conf\\templates\\70' , file: "${i}.png")}" alt="${i}"/>
 </g:each>

i put a random folder 70 in order to try a sample and it appears the correct name of the images like 0.png, 1.png ,2.png but it displays broken image symbol

Any ideas ?


Solution

  • createLinkTo() uses your applications name as a namespace which alone prevents this from working. Your links will end up in a form of src="yourappname/E:..."

    Also, grails does not expose resources under conf/ by default to web. Place your files under web-app/templates/ and change the createLinkTo to createLinkTo(dir:'templates', file: "${i}.png")

    Please include your grails version in the description and any plugins you use.