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 properties (like author, keyword, etc.). Afterwards some dtml-methods listed the content of the directories by mapping the properties of the documents. I now want to create a html-form which help the people to upload their files. 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? regards sim
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 properties | (like author, keyword, etc.). Afterwards some dtml-methods listed the content of | the directories by mapping the properties of the documents. | | I now want to create a html-form which help the people to upload their files. 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 --> <html> <head> <title tal:content="template/title">The title</title> </head> <body> <h2> <span tal:condition="template/title" tal:replace="template/title">optional template title</span> </h2> <form action="htpasswd_change.py" method="POST" enctype="multipart/form-data" > <input type="file" size="40" name="FileData"> <br> <input type="submit" size="40" name="Submit"> </form> </body> </html> The action is a Python Script that looks like this : ## Script (Python) "htpasswd_change.py" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## """ Description : Receive an uploaded 'htpasswd' file to be considered the authoritative authentication contents for the acl_users folder. """ request = container.REQUEST try : the_file = 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 -- If Microsoft would build a car... ... 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
Simon Brun writes:
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 properties (like author, keyword, etc.). Afterwards some dtml-methods listed the content of the directories by mapping the properties of the documents.
I now want to create a html-form which help the people to upload their files. 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? You need two things:
a form and an action; optionally, a result page You can start with the form "fileAdd.dtml" (search your computer for it). Extend it as necessary. In the action, you create (and upload) the file object ("manage_addFile") Then, you define the new properties you would like to have ("manage_addProperty"). Finally, you give them the correct values from the form with "manage_changeProperties". The necessary documentation is in the embedded Online help: Zope Help -> API Reference -> File PropertyManager Search the archives and Zope.org for the relevant methods to find examples and more information. Dieter
hi Thank you all for answering me :) Here is a test script which one you can upload files through a html formular and they will be added to a choosen folder. The code looks like this (the var "upload_dir" have to exist. I access the file like this: http://myintranet.com/addFile?upload_dir=CURRENT_FOLDER): <dtml-var standard_html_header> <dtml-if action> <dtml-with "new_intranet"> <dtml-with "_[upload_dir]"> <dtml-call "_[content_dir].manage_addFile(id=content_id, title=content_title, file=content_file)"> <dtml-call "_[content_dir]._[content_id].manage_addProperty('author', worker, 'string')"> <dtml-call "_[content_dir]._[content_id].manage_addProperty('comments', comment, 'line')"> </dtml-with> </dtml-with> <h3>Successfully uploaded</h3> The file named <b><dtml-var content_id></b> with the title <b><dtml-var content_title></b> was uploaded successfully into folder <b><dtml-var content_dir></b>! <br> <br> <a href="<dtml-var content_dir>">back</a> <dtml-else> <h3>File upload</h3> <form action="addFile" method="post" enctype="multipart/form-data"> <input type="hidden" name="action" value="1"> <input type="hidden" name="upload_dir" value="<dtml-var upload_dir>"> <table border="0"> <tr> <th align="left">Choose the directory</th> </tr> <dtml-with "new_intranet"> <dtml-with "_[upload_dir]"> <dtml-in "objectIds('Folder')"> <dtml-let folder=sequence-item> <tr><td><input type="radio" name="content_dir" value="<dtml-var folder>"> <dtml-var folder></td></tr> </dtml-let> </dtml-in> </dtml-with> </dtml-with> <tr> <th align="left"><br>Responsible / author</th> </tr> <tr> <td><input type="text" name="worker"></td> </tr> <tr> <th align="left"><br>Choose the file name</th> </tr> <tr> <td><input type="text" name="content_id"></td> </tr> <tr> <th align="left"><br>Choose a title (will be displayed as link)</th> </tr> <tr> <td><input type="text" name="content_title"></td> </tr> <tr> <th align="left"><br>Choose the file</th> </tr> <tr> <td><input type="file" name="content_file"></td> </tr> <tr> <th align="left"><br>Comments</th> </tr> <tr> <td><textarea name="comment" cols="50" rows="5"></textarea></td> </tr> <tr> <td><br><input type="submit" value="Upload File"></td> </tr> </table> </form> </dtml-if> <dtml-var standard_html_footer> The code works fine, when I comment out the "manage_addProperty"-Stuff. I can add properties to files without a problem, but not to the file I just uploaded. When I try, I get a "Authorization required" window! Can someone explain me why and how I can fix it? regards simon
participants (3)
-
Derrick 'dman' Hudson -
Dieter Maurer -
Simon Brun