开发者

download file with submitToRemote

开发者 https://www.devze.com 2023-03-14 16:59 出处:网络
I\'m in a jquery di开发者_如何学Goalog and I would like to download a file that requires a form submission within the dialog.I would like to use the g:submitToRemote tag to call the download but i\'m

I'm in a jquery di开发者_如何学Goalog and I would like to download a file that requires a form submission within the dialog. I would like to use the g:submitToRemote tag to call the download but i'm not sure where to send the data since it's a ajax call. My current code is below...

GSP...

        <g:submitToRemote class="download" controller="thingController" action="downloadInDialog" value="&nbsp;" />
    </div>
</g:form>

Controller...

def downloadInDialog = {
    def thingInstance = Thing.get(params.id)

    if (thingInstance) {
        def fileResource = thingInstance.fileResource;

        response.setContentType(fileResource.fileType);
        response.setHeader("Content-disposition", "attachment;filename=${fileResource.name}")

        response.outputStream << fileResource.toNewInputStream() // Performing a binary stream copy

    }

}


I removed the submitToRemote and used a standard form submit in the jquery dialog and everything worked fine.

Thanks for everyone's help!

0

精彩评论

暂无评论...
验证码 换一张
取 消