gpt4 book ai didi

image - 使用 grails 和 oracle 保存和显示 blob 数据

转载 作者:行者123 更新时间:2023-12-02 15:33:43 25 4
gpt4 key购买 nike

我想使用 grails 将图像保存并显示到 oracle 10g 中的 blob 字段中。如果我在数据库中使用 Long raw 字段,那么它可以工作。但在 blob 字段的情况下
它保存但不显示在 View 页面中。

这是代码:

        //Domain
class Hotel{

byte [] pic_

static mapping={}


static constraints = {}


}

//Controller

Class contrl
{

def save() {
def hotelInstance = new Hotel(params)
if (!hotelInstance.save(flush: true)) {
render(view: "create", model: [hotelInstance: hotelInstance])
return
}

flash.message = message(code: 'default.created.message', args: [message(code: 'hotel.label', default: 'Hotel'), hotelInstance.id])
redirect(action: "show", id: hotelInstance.id)
}

}


def displayLogo () {
def sponsor = Hotel.get(params.id)
response.contentType = "image/jpg"
response.contentLength = sponsor?.pic_.length
response.outputStream.write(sponsor?.pic_)
response.outputStream.flush()
}

//View
<td><img src="${createLink(action:'displayLogo ', id:hotelInstance?.id)}" height="42" width="42" /> </td>

最佳答案

使用 Blob 。你的 mime 类型也是错误的

Hotel hotel = Hotel.get(params.id)
response.contentType = 'image/jpeg'
response.outputStream << hotel.pic_
response.outputStream.flush()

我还看到 createLink 中您的操作名称后面有一个空格.我怀疑它会破坏任何东西,但请摆脱它。

关于image - 使用 grails 和 oracle 保存和显示 blob 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15182527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com