我有一个控制器,它连接到一个URL来检索一个csv文件.
我能够使用以下代码在响应中发送文件,这很好.
def fileURL = "www.mysite.com/input.csv"
def thisUrl = new URL(fileURL);
def connection = thisUrl.openConnection();
def output = connection.content.text;
response.setHeader "Content-disposition", "attachment;
filename=${'output.csv'}"
response.contentType = 'text/csv'
response.outputStream << output
response.outputStream.flush()
Run Code Online (Sandbox Code Playgroud)
但是我认为这个方法不适合大文件,因为整个文件被加载到控制器内存中.
我希望能够通过块读取文件块,并通过块将文件写入响应块.
有任何想法吗?