How to display image in grails GSP?

Posted by Walter on Stack Overflow See other posts from Stack Overflow or by Walter
Published on 2008-11-03T17:10:02Z Indexed on 2010/03/14 3:15 UTC
Read the original article Hit count: 557

Filed under:
|
|
|

I'm still learning Grails and seem to have hit a stumbling block.

Here are the 2 domain classes:

class Photo {
    byte[] file 

    static belongsTo = Profile
}


class Profile {
    String fullName
    Set photos

    static hasMany = [photos:Photo]		
}

The relevant controller snippet:

class PhotoController {

..... def viewImage = {

  def photo = Photo.get( params.id )
  byte[] image = photo.file 
  response.outputStream << image

}

...... }

Finally the GSP snippet:

<img class="Photo" src="${createLink(controller:'photo', action:'viewImage', id:'profileInstance.photos.get(1).id')}" />

Now how do I access the photo so that it will be shown on the GSP? I'm pretty sure that profileInstance.photos.get(1).id is not correct. Thanks!!

© Stack Overflow or respective owner

Related posts about grails

Related posts about image