Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 使用grails下载大型文件_File_Grails_Groovy_Download - Fatal编程技术网

File 使用grails下载大型文件

File 使用grails下载大型文件,file,grails,groovy,download,File,Grails,Groovy,Download,我正在开发一个grails应用程序,它具有文件共享功能。它将文件上传到服务器上,并允许用户从服务器下载文件。我为此使用了以下代码: def file = new java.io.File(filePath) response.setContentType( "application-xdownload") response.setHeader("Content-Disposition", "attachment;filename=${fileName}") response.getOutputS

我正在开发一个grails应用程序,它具有文件共享功能。它将文件上传到服务器上,并允许用户从服务器下载文件。我为此使用了以下代码:

def file = new java.io.File(filePath)
response.setContentType( "application-xdownload")
response.setHeader("Content-Disposition", "attachment;filename=${fileName}")
response.getOutputStream() << new ByteArrayInputStream(file.getBytes())
那么,我该怎么做才能使我的应用程序能够下载大文件呢?
谢谢

替换文件,而不是将文件加载到内存中

response.getOutputStream() << new ByteArrayInputStream(file.getBytes())
response.getOutputStream()
response.getOutputStream() << new ByteArrayInputStream(file.getBytes())
file.withInputStream { response.outputStream << it }