[Zope] Re: file upload formular

Derrick 'dman' Hudson dman@dman.ddts.net
Wed, 12 Jun 2002 12:24:02 -0500

Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Jun 12, 2002 at 04:30:12PM +0200, Simon Brun wrote:
| hi all
| For our intranet I'm going to improve the file upload. In the past, the
| workers had to upload their files via the ZMI. They had to add some prope=
| (like author, keyword, etc.). Afterwards some dtml-methods listed the con=
tent of
| the directories by mapping the properties of the documents.=20
| I now want to create a html-form which help the people to upload their fi=
les. In
| this form they have to insert the properties and after pressing the submit
| button, the file should be uploaded into Zope.
| I'm sure this was done by other users before, but I didn't find something=
. Any
| good ideas or code out there?

I have a page that allows a file upload which is passed to a script.

The page is ZPT and looks like :

<!-- Zope Page Template -->

        <title tal:content=3D"template/title">The title</title>


           <span tal:condition=3D"template/title"
               tal:replace=3D"template/title">optional template title</span>

        <form action=3D"htpasswd_change.py"

            <input type=3D"file" size=3D"40" name=3D"FileData">
            <input type=3D"submit" size=3D"40" name=3D"Submit">



The action is a Python Script that looks like this :

## Script (Python) "htpasswd_change.py"
##bind container=3Dcontainer
##bind context=3Dcontext
##bind namespace=3D
##bind script=3Dscript
##bind subpath=3Dtraverse_subpath

Description   :
     Receive an uploaded 'htpasswd' file to be considered the authoritative
     authentication contents for the acl_users folder.

request =3D container.REQUEST

try :
    the_file =3D request["FileData"]
    the_file.readlines  # just verify that the object is file-like
except KeyError :
    print "Error: a file must be specified"
    return printed

# Followed by the rest of the logic to parse the file and manipulate
# the acl_users folder.  The "success" output is also simply printed
# and the end is a 'return printed' line.



If Microsoft would build a car...
=2E.. Occasionally your car would die on the freeway for no reason. You
would have to pull over to the side of the road, close all of the car
windows, shut it off, restart it, and reopen the windows before you
could continue. For some reason you would simply accept this.
Jabber ID : dman@dman.ddts.net
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg

Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org