[Zope] http file download method
Giuseppe Bonelli
giuseppe.bonelli at tiscalinet.it
Tue Dec 14 06:15:57 EST 2004
Hi list,
I have a small python product to download files via http. For various
reasons (e.g. to have per user log files and for other security issues)
I read the files from the file system and then stream them using a
method. Here is a code snippet:
class container(Folder):
"general container"
...
def getFile(self, fname, REQUEST):
"read a file from the filesystem and stream it through http"
user=str(getSecurityManager().getUser())
userDir=userDirs[user]
logFilePath=userDir+'downloadLog.txt'
logFile=open(logFilePath, 'a')
userDir+='download\\'
path=userDir+fname
f=open(path, 'rb')
cnt=f.read()
f.close()
res=REQUEST.RESPONSE
(type, enc)=guess_content_type(name=fname, body=cnt)
res.setHeader('content-type', type)
res.setHeader('content-length', os.stat(path)[6])
res.setHeader('last-modified', os.path.getmtime(path))
res.setHeader('accept-ranges', "none")
res.write(cnt)
s='%s\t%s\t%s\n' % (user, strftime("%A %d %B %Y - %H:%M",
localtime()),fname)
logFile.write(s)
logFile.close()
The method getFile is called from the web passing the fname parameter in
the url, e.g http://foo.bar/getFile?fname=xxx.xxx
Everything works nicely, but obviously on the download dialog box
displayed by the client browser you get the name of the download method
"getFile" instead of the name of the file and this can confuse some
users.
Any ideas to resolve this?
TIA,
__peppo
More information about the Zope
mailing list