file upload from python script
Hi, I'm trying to do a file upload from inside a python script that takes the file's path and the target folder object as args. When I try manage_addFile or manage_upload, the content of the new Zope-file is the path of the file I wanted to upload and not the file itself. File upload works fine from a DTML-Method which takes the file's path (and something more I think) from a DTML-Document using a <input type="file">-tag. I found them somewhere in the internet and I'll list them below in case they'll help you helping me. Thanks in advance Horst DTML-Doc "DateiBagger": <html> <h2><dtml-var title_or_id></h2> <table border=0> <form action="SchaufelBagger" enctype="multipart/form-data" method="post"> <tr> <td><b>Datei:</b></td> <td><input type="file" name="DateiName"></td> </tr> <tr><td></td><td> <input type=submit value="HochSchaufeln"></td></tr> </form> DTML-Meth "SchaufelBagger", called by the previous document: <html> <h2><dtml-var document_id></h2> <dtml-let fname="_.string.split(DateiName.filename,'\\')[-1]"> <dtml-with upload> <dtml-if "_.has_key(_['fname'])"> <dtml-call "_[_['fname']].manage_upload(REQUEST.form['DateiName'])"> <p><dtml-var fname> wurde hochgeschaufelt, alte Fassung wurde ersetzt.</p> <dtml-else> <dtml-call "manage_addFile(_['fname'], REQUEST.form['DateiName'])"> <p><dtml-var fname> wurde hochgeschaufelt.</p> </dtml-if> <form action="upload/<dtml-var fname>" method="post"> <input type=submit value="Ansehen"> </form> </dtml-with> </dtml-let> <dtml-var standard_html_footer> </table> <dtml-var standard_html_footer> _________________________________________________________________ Downloaden Sie MSN Explorer kostenlos unter http://explorer.msn.de/intl.asp
For me, it's easier in pure Python, but I upload the data in the filesystem (not in ZODB) Anyway, you can get the uploaded content (not the file path) with the "read" method. In your case, "DateiName.read()" returns the file's content. A propos, "\\" is the path separator and will work with Win32 IE5 that gives the full client side path to the file. Macintosh IE5 gives only the name of the file with no extension since Macintosh has hidden "type/creator" equivalent in the resource fork of the file (inside the file). Check the DateiName.filename with various client OS / browsers and you'll get various results... 8(( ----- Original Message ----- From: "Horst Wald" <horstwald@hotmail.com> To: <zope@zope.org>; <website-talk-admin@list.ora.com> Sent: Monday, September 03, 2001 6:19 PM Subject: [Zope] file upload from python script
Hi,
I'm trying to do a file upload from inside a python script that takes the file's path and the target folder object as args.
When I try manage_addFile or manage_upload, the content of the new Zope-file is the path of the file I wanted to upload and not the file itself.
File upload works fine from a DTML-Method which takes the file's path (and something more I think) from a DTML-Document using a <input type="file">-tag. I found them somewhere in the internet and I'll list them below in case they'll help you helping me.
Thanks in advance
Horst
DTML-Doc "DateiBagger":
<html> <h2><dtml-var title_or_id></h2> <table border=0> <form action="SchaufelBagger" enctype="multipart/form-data" method="post"> <tr> <td><b>Datei:</b></td> <td><input type="file" name="DateiName"></td> </tr> <tr><td></td><td> <input type=submit value="HochSchaufeln"></td></tr> </form>
DTML-Meth "SchaufelBagger", called by the previous document:
<html> <h2><dtml-var document_id></h2> <dtml-let fname="_.string.split(DateiName.filename,'\\')[-1]"> <dtml-with upload> <dtml-if "_.has_key(_['fname'])"> <dtml-call "_[_['fname']].manage_upload(REQUEST.form['DateiName'])"> <p><dtml-var fname> wurde hochgeschaufelt, alte Fassung wurde ersetzt.</p> <dtml-else> <dtml-call "manage_addFile(_['fname'], REQUEST.form['DateiName'])"> <p><dtml-var fname> wurde hochgeschaufelt.</p> </dtml-if>
<form action="upload/<dtml-var fname>" method="post"> <input type=submit value="Ansehen"> </form>
</dtml-with> </dtml-let> <dtml-var standard_html_footer>
</table> <dtml-var standard_html_footer>
_________________________________________________________________ Downloaden Sie MSN Explorer kostenlos unter http://explorer.msn.de/intl.asp
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Horst Wald writes:
I'm trying to do a file upload from inside a python script that takes the file's path and the target folder object as args.
When I try manage_addFile or manage_upload, the content of the new Zope-file is the path of the file I wanted to upload and not the file itself. This means, you should pass the FileUpload object and not the filename :-)
Dieter
participants (3)
-
Dieter Maurer -
Gilles Lenfant -
Horst Wald