Jim Gallacher
jpg at jgassociates.ca
Tue Jun 6 08:38:39 EDT 2006
Deron Meranda wrote: > On 6/5/06, Webb Sprague <webb.sprague at gmail.com> wrote: >> Is there anyway to specify programmatically a good default name for a >> binary file? My URL is /blah/objectDump?id=5, and the default >> filename Windows gives for saving it is "objectDump"--I would like to >> generate the filename and have it be something like >> "forecast-object-5.txt' > > Perhaps the best way is to send a Content-Disposition header > (in addition to your Content-Type header). You'll usually send > one of these two variants: > > Content-Disposition: inline; filename=forecast-object-5.txt > Content-Disposition: attachment; filename=forcast-object-5.txt > > If the filename contains any HTTP special characters (called > "separators") then you'll need to quote the filename using > the HTTP quoted-string syntax. > > The "inline" form will cause the browser to try to display the > file inline, if possible (e.g., displayed in the browser window). > The "attachment" form will cause the browser to open a > "save as" dialog, using the filename parameter as the > suggested filename. > > The other (less desirable) way is to construct your URL > with extra unused path components at the end, such that > the last one is the filename. > > You can also use some of the maps and functions in the > standard Python module "mimetypes" to help you construct > a proper filename (such as picking an extension given > a content-type). And once you know the name of the header you are looking for, the RFCs become your friends. http://rfc.net/rfc2616.html#s19.5.1 http://rfc.net/rfc2183.html Jim
|