title: How can I display a jpeg image in GSP, encoded in base64, from a controller
body: <pre><code>  &lt;img  src="data:image/jpeg;base64,${createLink(controller:'Photo', action:'showEncoded', id:"${PhotoInstance.id}")}" width='300' /&gt;
  </code></pre>
  
  <p>I'm just starting out with grails and this is my first question on Stackoverflow. My controller returns an image encoded in base64 but the above code in gsp complains that there are errors in the  image.</p>
  
  <p>The domain class Photo stores the JPEG image in</p>
  
  <pre><code>byte[] imagePhoto
  </code></pre>
  
  <p>and saved as binary</p>
  
  <p>The showEncoded method is defined in my controller and encodes imagePhoto as a base64 string, returning it to the requested GSP.</p>
  
  <pre><code> def showEncoded(Photo DBPhotoInstance) {
      String encoded = DBPhotoInstance.imagePhoto.encodeBase64().toString()
      response.outputStream &lt;&lt; encoded
      response.outputStream.flush()
  }
  </code></pre>
  
  <p>I've also checked to make sure the image is a JPEG file.
  Any help, direction or guidance thanks!</p>