File 使用grails下载大型文件
我正在开发一个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
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 }