I have a JDO class and a helper class Image to store images within a byte array
JDO class:
@PersistenceCapable
class Recipe{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long key
@Persistent
private String description
@Persistent(serialized = "true")
private Image image;
}
Image class:
class Image implements Serializable {
private byte[] content
private String filename
private String mimeType
}
In the gsp page I iterate through the recipes and want to show the images. I could do a controller like this to get the image src.
def viewImage= {
//retrieve photo code here
response.setHeader("Content-disposition", "attachment; filename=${photo.name}")
response.contentType = photo.fileType //'image/jpeg' will do too
response.outputStream << photo.file //'myphoto.jpg' will do too
response.outputStream.flush()
return;
}
But this way I have to send the key of the recipe to this controller and load the image again from the datastore. (I already have loaded it actually. But I think I can not send this data to the controller. Can I ?) Is there not a more convenient way to show the image from a byte array in gsp page ?