using grails and google app engine to store image as blob and the view dynamically
Posted
by mswallace
on Stack Overflow
See other posts from Stack Overflow
or by mswallace
Published on 2010-05-24T00:00:39Z
Indexed on
2010/05/24
0:11 UTC
Read the original article
Hit count: 982
I am trying to dynamically display an image that I am storing in the google datastore as a Blob. I am not getting any errors but I am getting a broken image on the page that I view.
Any help would be awesome!
I have the following code in my grails app
domain class has the following
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Long id
@Persistent
String siteName
@Persistent
String url
@Persistent
Blob img
@Persistent
String yourName
@Persistent
String yourURL
@Persistent
Date date
static constraints = {
id( visible:false)
}
My save method in the controller has this
def save = {
params.img = new Blob(params.imgfile.getBytes())
def siteInfoInstance = new SiteInfo(params)
if(!siteInfoInstance.hasErrors() ) {
try{
persistenceManager.makePersistent(siteInfoInstance)
} finally{
flash.message = "SiteInfo ${siteInfoInstance.id} created"
redirect(action:show,id:siteInfoInstance.id)
}
}
render(view:'create',model:[siteInfoInstance:siteInfoInstance])
}
My view has the following
<img src="${createLink(controller:'siteInfoController', action:'showImage', id:fieldValue(bean:siteInfoInstance, field:'id'))}"></img>
and the method in my controller that it is calling to display a link to the image looks like this
def showImage = {
def site = SiteInfo.get(params.id)// get the record
response.outputStream << site.img // write the image to the outputstream
response.outputStream.flush()
}
© Stack Overflow or respective owner