0
我想動態顯示一個圖像,我作爲一個Blob存儲在谷歌數據存儲區。我沒有收到任何錯誤,但是我在我查看的頁面上看到了一張破碎的圖像。使用grails和谷歌應用程序引擎來存儲圖像作爲blob和動態視圖
任何幫助將是真棒!
我在我的Grails應用程序有以下代碼
域類已經在控制器中執行以下
@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)
}
我保存方法有這個
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])
}
我的觀點有以下
<img src="${createLink(controller:'siteInfoController', action:'showImage', id:fieldValue(bean:siteInfoInstance, field:'id'))}"></img>
,並在我的控制器的方法,它是打電話來顯示一個鏈接的圖像看起來像這樣
def showImage = {
def site = SiteInfo.get(params.id)// get the record
response.outputStream << site.img // write the image to the outputstream
response.outputStream.flush()
}