gpt4 book ai didi

grails - Grails文件下载不起作用

转载 作者:行者123 更新时间:2023-12-02 16:03:52 25 4
gpt4 key购买 nike

我正在尝试编写一个 Controller 来下载文件。
我的域类如下所示:

class File {

String fileName
Byte[] fileBytes
Long fileSize
String fileType
String fileDescription
...
...
}

我的 Controller 如下所示:
def downloadFile = {
def file = File.findById(params.id)
if (file != null)
{
response.setContentType(file.fileType)
response.setHeader("Content-disposition", "attachment;filename=\"${file.fileName}\"")
response.outputStream << file.fileBytes
return
}

}

没有错误,但这是行不通的。谁能帮助我找出问题所在?

谢谢!

最佳答案

很久以前,我在上面写了一些代码片段。

http://lalitagarw.blogspot.com/2014/03/grails-forcing-file-download.html

这可以为您提供帮助。

但是,尝试添加

response.outputStream << file.fileBytes
webRequest.renderView = false

而且不需要退货。

关于grails - Grails文件下载不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27555879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com