Making a folder-like object?
The Subject line is not the question; it's only a possible start-of-answer... I'm building an application, using Zope and a database, where users can upload files. These files are stored as BLOBs in the DB, not in the ZODB. The problem is to get back the filename when a user downloads a file. I. e., I'll have things like: <a href="http://my.host/retrieve?id=42">results.xls</a> where ``retrieve´´ is the script. I would like instead to be able to present an address like: <a href="http://my.host/retrieve/42/results.xls">results.xls</a> This is the only way I know of to pass the filename to the client (though I'd be happy to be corrected). So: Is this possible directly? Otherwise, should I start hacking, e.g., Gary Poster's FakeFolder, or are there better ways? Thanks, Yves [Please CC: me answers as I'm not on the list]
Hi. This sounds like a job for a framework like ZPatterns which already addressed this issues. If you only think about a quick hack, then look forward on using a Script(Python) with the traverse_subpath approach. Greetings. Christian On Fri, Mar 01, 2002 at 02:33:10PM +0100, Yves Bastide wrote:
The Subject line is not the question; it's only a possible start-of-answer...
I'm building an application, using Zope and a database, where users can upload files. These files are stored as BLOBs in the DB, not in the ZODB.
The problem is to get back the filename when a user downloads a file. I. e., I'll have things like: <a href="http://my.host/retrieve?id=42">results.xls</a> where ``retrieve´´ is the script.
I would like instead to be able to present an address like: <a href="http://my.host/retrieve/42/results.xls">results.xls</a>
This is the only way I know of to pass the filename to the client (though I'd be happy to be corrected).
So:
Is this possible directly? Otherwise, should I start hacking, e.g., Gary Poster's FakeFolder, or are there better ways?
-- Christian Theune - ct@gocept.com gocept gmbh & co.kg - schalaunische strasse 6 - 06366 koethen/anhalt tel.+49 3496 3099112 - fax.+49 3496 3099118 mob. - 0178 48 33 981 reduce(lambda x,y:x+y,[chr(ord(x)^42) for x in 'zS^BED\nX_FOY\x0b'])
On Fri, 1 Mar 2002, Yves Bastide wrote:
<a href="http://my.host/retrieve?id=42">results.xls</a> where ``retrieve�� is the script.
I would like instead to be able to present an address like: <a href="http://my.host/retrieve/42/results.xls">results.xls</a>
This is the only way I know of to pass the filename to the client (though I'd be happy to be corrected).
Make retrieve set the correct content-type and content-disposition in the response's headers, and you'll be able to choose the name of the file. an example with application/pdf as the content-type : <UNTESTED> ... filename = "myfile.pdf" REQUEST.RESPONSE.setHeader('Content-Type', 'application/pdf') REQUEST.RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s' % filename) return filedata() ... <UNTESTED> filedata() shoudl retunr the actual file contents. hth. Jerome Alet - alet@unice.fr - http://cortex.unice.fr/~jerome Fac de Medecine de Nice http://wwwmed.unice.fr Tel: (+33) 4 93 37 76 30 Fax: (+33) 4 93 53 15 15 28 Avenue de Valombrose - 06107 NICE Cedex 2 - FRANCE
Jerome Alet wrote:
On Fri, 1 Mar 2002, Yves Bastide wrote:
<a href="http://my.host/retrieve?id=42">results.xls</a> where ``retrieve´´ is the script.
I would like instead to be able to present an address like: <a href="http://my.host/retrieve/42/results.xls">results.xls</a>
This is the only way I know of to pass the filename to the client (though I'd be happy to be corrected).
Make retrieve set the correct content-type and content-disposition in the response's headers, and you'll be able to choose the name of the file.
an example with application/pdf as the content-type :
<UNTESTED> ... filename = "myfile.pdf" REQUEST.RESPONSE.setHeader('Content-Type', 'application/pdf') REQUEST.RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s' % filename) return filedata() ... <UNTESTED>
filedata() shoudl retunr the actual file contents.
hth.
Yes, this works enough (wget doesn't grok it, but Mozilla and IE use the filename in their Save As dialog). Will do! Thanks Jérôme, Yves
Jerome Alet - alet@unice.fr - http://cortex.unice.fr/~jerome Fac de Medecine de Nice http://wwwmed.unice.fr Tel: (+33) 4 93 37 76 30 Fax: (+33) 4 93 53 15 15 28 Avenue de Valombrose - 06107 NICE Cedex 2 - FRANCE
Yves Bastide <Yves.Bastide@irisa.fr> writes:
Is this possible directly?
Pythonscripts are traversable - you can have a Python script "retrieve" that handles the additional path information as parameters or simply ignores some parts. Regards, Frank
participants (4)
-
Christian Theune -
Frank Tegtmeyer -
Jerome Alet -
Yves Bastide