Grails: displaying created image in gsp

前端 未结 8 1955
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 10:07

I\'m very new to Grails so there\'s probably a very simple answer to this question. I\'m trying to display a dynamically created image in a gsp. The image is NOT stored in

相关标签:
8条回答
  • 2020-11-29 11:00

    Your gsp:

    <img src="${createLink(controller: "image", action: "draw")}" />
    

    Your controller:

    def draw() {
      byte[] imageInBytes = imageService.getImageInBytes() //should return byte array 
    
      response.with{
        setHeader('Content-length', imageInBytes.length.toString())
        contentType = 'image/jpg' // or the appropriate image content type
        outputStream << imageInBytes
        outputStream.flush()
      }
    }
    
    0 讨论(0)
  • 2020-11-29 11:05

    For any reasons the above solutions does not display any image. I used:

    <img src='${createLink(controller: "myController", action: "displayGraph")}' />
    

    instead.

    0 讨论(0)
提交回复
热议问题