Saturday, April 12, 2008

How to change the name of file to be downloaded..

Example from mailing list:

If I have a controller say:

def genFile {

ByteArrayOutputStream out = new ByteArrayOutputStream();

.... read data into outputstream here

response.setContentType('application/exe')
out.writeTo(response.getOutputStream())
out.close()
}

The file name presented to the user for save would be 'genFile'

However, adding the following in the beginning of controller would force the browser to recognize a different name:
response.addHeader("content-disposition", "attachment;filename=myfilename.ext")

2 comments:

iamsteveholmes said...
This comment has been removed by the author.
iamsteveholmes said...

Sorry, I intended to comment on your Hudson with Grails post.