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

标签 image grails blob

我想使用 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/

相关文章:

ruby-on-rails - Goji,RoRails或Grails for “Social Network”

android - 使用 blob 的最大 SQLite 大小

node.js - 如何在Nodejs中将word文档转换为pdf

javascript - 如何在 Javascript 中获得透明的粘贴图像

html - CSS 文件不再更新。浏览器不接受我的更改

grails - 整数枚举和g:select

grails - GORM 标准查询 : Finding Children with specific properties

azure - 神秘消失的Azure开发存储 Assets

html - 显示 100% 的背景

java - 用 Java 编写图像元数据,最好是 PNG