Grails控制器:如何从字节数组渲染图像

时间:2015-12-19 13:20:19

标签: image grails bytearray httpbuilder

我有字节数组byteImg但我希望在我的控制器jpeg中从字节数组中进行渲染:

    def getSelfie = new HTTPBuilder()
    getSelfie.request(fullSelfieUrl, GET, JSON) { req ->
        headers.'X-DreamFactory-Session-Token' = session_id
        headers.'X-DreamFactory-Application-Name' = 'checkReg'
        response.success = { resp, reader ->
            assert resp.statusLine.statusCode == 200
            println "Get response: ${resp.statusLine}"
            println "Content-Type: ${resp.headers.'Content-Type'}"
            resp = reader as grails.converters.JSON

            String str = resp.toString()
            JSONObject jsonObject = new JSONObject(str)
            selfieRend = jsonObject.getString("selfie")
            byteImg = selfieRend.getBytes()

            render byteImg
            return byteImg
        }
        response.'404' = {
            println 'Information not found'
        }
    }

怎么做?非常感谢你

1 个答案:

答案 0 :(得分:0)

我还没有对其进行测试,但根据wiki,这应该有效:

1