title: How to display image in grails GSP?
body: <p>I'm still learning Grails and seem to have hit a stumbling block.</p>
  
  <p><strong>Here are the 2 domain classes:</strong></p>
  
  <pre><code>class Photo {
      byte[] file 
  
      static belongsTo = Profile
  }
  
  
  class Profile {
      String fullName
      Set photos
  
      static hasMany = [photos:Photo]     
  }
  </code></pre>
  
  <p><strong>The relevant controller snippet:</strong>   </p>
  
  <pre><code>class PhotoController {
  
      def viewImage = {
  
        def photo = Photo.get( params.id )
        byte[] image = photo.file 
        response.outputStream &lt;&lt; image
  
      } 
  } 
  </code></pre>
  
  <p><strong>Finally the GSP snippet:</strong></p>
  
  <pre><code>&lt;img class="Photo" src="${createLink(controller:'photo', action:'viewImage', id:'profileInstance.photos.get(1).id')}" /&gt;
  </code></pre>
  
  <p>Now how do I access the photo so that it will be shown on the GSP? I'm pretty sure that 
  <code>profileInstance.photos.get(1).id</code> is not correct.</p>