Image Grails Webflow显示图像-流范围

Image Grails Webflow显示图像-流范围,image,grails,scope,spring-webflow,Image,Grails,Scope,Spring Webflow,我已将图像保存到命令对象中的字节[],并希望在createFlow webflow的下一阶段中显示它 我试图避免在webflow期间使用文件系统和/或数据库系统来存储图像 通常,要查看图像,我会从gsp调用renderImage: class ArtefactController { def createFlow = { ............ } def renderImage = { def ArtefactInstance = Artefact

我已将图像保存到命令对象中的字节[],并希望在createFlow webflow的下一阶段中显示它

我试图避免在webflow期间使用文件系统和/或数据库系统来存储图像

通常,要查看图像,我会从gsp调用renderImage:

class ArtefactController {

    def createFlow = {
       ............
    }

def renderImage = {

    def ArtefactInstance = Artefact.findById(params.id)
    if(ArtefactInstance?.image) {
        response.setContentLength(ArtefactInstance.image.length)
        response.outputStream.write(ArtefactInstance.image)
    }
    else {
        response.sendError(404)
    }
}
但是,对于webflow,当我尝试从gsp调用renderFlowImage时:

def renderFlowImage = {
    if(flow.artefactCommand?.image) {
        response.setContentLength(flow.artefactCommand.image.length)
        response.outputStream.write(flow.artefactCommand.image)
    }
    else {
        response.sendError(404)
    }
}
中的流范围不可访问


有什么建议吗?

我假设您通过img标记通过第二个http请求点击流视图中的renderFlowImage操作,例如:

<img src="${createLink(action:'renderFlowImage')}" />

这是行不通的,因为首先,您需要传入一个“flowExecutionKey”,grails使用它来匹配请求和流。 可以解决这个问题,但最好在流的下一个视图的渲染阶段使用img标记中的数据URI渲染图像。使用rendering插件可以很容易地做到这一点,它提供了一些方便的标记(除其他外)来使用数据uri呈现内联图像。 因此,在下一个流视图中,您可以通过调用渲染插件的“inline”标记来替换现有的img标记:

<rendering:inlineJpeg bytes="${artefactCommand.image}" /> 


但是要小心——数据URI方法有一些限制需要注意(请参阅)

谢谢你的回复,这太好了。您知道我将如何处理flowExecutionKey的解决方案吗?对于解决方案,我想您可能能够适应以下文章中描述的技术:和。但我个人不想用一个专门渲染图像的步骤来污染我的流程。您还可以查看“Ajaxflow”插件。