[Zope] one time downloads
Jim Penny
jpenny@universal-fasteners.com
Thu, 19 Jun 2003 15:33:59 -0400
On Wed, 18 Jun 2003 10:51:38 -0700 (PDT)
Ed Colmar <ed@greengraphics.net> wrote:
>
> Hey fellow zope fiends.
>
> I've got a little project I'm working on that involves setting up
> multiple one-time downloads.
>
> I'm curious if anyone out there has done something similar that would
> like to share ideas and or code.
>
> My concept was to have all the files in a secure directory somewhere.
> Make a temporary directory somewhere with a random id
> "oahnw3487cfyawcry7baw385vbyawy348vyaw" or whatever... Set the
> directory name and a flag into a db somewhere. Then after the
> download is complete(or after a certain amount of time, delete the dir
> and the files.
Yes, it is not real hard. You will probably need an external method.
Here is what I do, more or less:
import sha, os
my_secret='Put your site secret string here'
f_base='absolute path to file base'
def upload(self, name, attachment):
# make sure index.html is there
# to block people from simply reading the directory
if not os.access(f_base+'/index.html', os.F_OK):
f.open('index.html', w)
f.write("""<html><head><title>No Peaking</title></head>
<body>No Peaking!</body></html>"""
f.close()
so=sha.new(my_secret+name)
hx=so.hexdigest()
fpth=f_base+name+hx+'.html' # or whatever extension
f=open(fpth, 'wb')
while 1:
s=attachment.read(4096)
if not s:
break
once = 1
f.write(s)
f.close()
return fpth
Then you can use fpth to compose your email, athough you probably
actually want to construct an URL, not a file path.
And a simple cron job can take care of cleaning the directory for you
periodically. Just try to avoid deleting index.html.
Jim Penny
> Anyone have something like this already?
>
> Thanks!
>
> -ed-
>
> --
> Green Graphics ::: Print and Web Design ::: 510.923.0000
>
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://mail.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
>
>