2
  <img  src="data:image/jpeg;base64,${createLink(controller:'Photo', action:'showEncoded', id:"${PhotoInstance.id}")}" width='300' />

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.

The domain class Photo stores the JPEG image in

byte[] imagePhoto

and saved as binary

The showEncoded method is defined in my controller and encodes imagePhoto as a base64 string, returning it to the requested GSP.

 def showEncoded(Photo DBPhotoInstance) {
    String encoded = DBPhotoInstance.imagePhoto.encodeBase64().toString()
    response.outputStream << encoded
    response.outputStream.flush()
}

I've also checked to make sure the image is a JPEG file. Any help, direction or guidance thanks!

Nick
  • 43
  • 4
  • https://github.com/vahidhedayati/grails-bean-validation-examples it is covered on this test site has a video too. Hopefully it will unravel your issue – V H Sep 18 '16 at 20:11
  • Have you seen this ? http://stackoverflow.com/questions/34371245/grails-controller-how-render-image-from-byte-array – quindimildev Sep 19 '16 at 08:07
  • @vahid. Thanks the example you posted provided an alternative answer to my problem. – Nick Sep 19 '16 at 19:13
  • @Nick no problems. A little complex but the bean is a solid image manipulation tool. Took me a while to put together and hopefully will benefit others too – V H Sep 19 '16 at 19:33

0 Answers0