[Zope] Forcing someone to download a .html file

Peter Bengtsson mail@peterbe.com
Wed, 27 Feb 2002 11:27:08 +0100


I have a little method in my product class that when called returns an XML file and Internet Explorer asks if you want to Open it or Save it.
That's almost what I want and it working in IE(5or6) is only important. It's just one windows user who will need this.

What I want ultimatly is that when editing "foo.html" in the ZMI there will be the option of downloading it "Click to download foo.html". Clicking that will automatically show the little Save/Open dialog for download. Ideally


Here's the code::

    def Download(self, REQUEST, RESPONSE):
        """ Download the document source and PUT it forward """
        doc_src = self.document_src(REQUEST, RESPONSE)

	from whrandom import random
	
	id = "File"+ `random()*10`[2:4] 
	suffix = 'xml'
	
        f=StringIO()
        f.write(doc_src+'\n')
        RESPONSE.setHeader('Content-type','application/data')
        RESPONSE.setHeader('Content-Disposition',
                'inline;filename=%s.%s' % (id, suffix))
        return f.getvalue()

That works fine but I don't want to save it as .xml because that makes it difficult to open in Dreamweaver.
Using 'html' for the suffix makes IE trying to open it immediatly.

Desperate for some helpful advice or hints.
Peter