[Zope] Re: file upload formular

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


--tThc/1wpZn/ma/RB
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
|=20
| 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=
rties
| (like author, keyword, etc.). Afterwards some dtml-methods listed the con=
tent of
| the directories by mapping the properties of the documents.=20
|=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.
|=20
| 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 -->
<html>

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

   <body>

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

        <form action=3D"htpasswd_change.py"
            method=3D"POST"
            enctype=3D"multipart/form-data"
            >

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

        </form>

    </body>
</html>


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
##parameters=3D
##title=3D
##

"""
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.
#


HTH,
-D

--=20

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.
=20
Jabber ID : dman@dman.ddts.net
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg

--tThc/1wpZn/ma/RB
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iEYEARECAAYFAj0Hg7IACgkQO8l8XBKTpRSqoQCgnBa0r69eXMlDDgOuqL7UwKg4
f1QAn1Y/8q+K0qSpAum8YjV0ZL9alJ0+
=2FUn
-----END PGP SIGNATURE-----

--tThc/1wpZn/ma/RB--