Setting the filename for generated files for download

Purpose

When creating dynamically generated output, you may want to set the default filename which will be provided if the file is saved. This example shows how to specify the default filename used in the "Save file as" dialog box.

 

From a Python Script

 

 

filename = 'MySpecifiedFilename.txt' RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s' % (filename));

 

 

 

From DTML

 

 

<dtml-call "RESPONSE.setHeader('Content-Disposition', 'attachment; filename=MySpecifiedFilname.txt')"><br />

 

 

 

Additional Notes

Additionally, you may wish to force the browser to prompt to save the file. Dependent on the configuration of the client browser, the save dialog box will appear with the name of the file set as above. You can do that by setting the following header:

 

RESPONSE.setHeader('Content-Type', 'application/force-download');<br />

 

 

Last modified: 2014/01/30 10:54:52.776794 US/Eastern by christopher.n.deckard.1
Created: 2007/03/22 16:32:42.655000 GMT-4 by brian.r.brinegar.1.

Categories

Search

Type in a few keywords describing what information you are looking for in the text box below.

Admin Options: Edit this Document