[Zope] file upload from python script
Horst Wald
horstwald@hotmail.com
Tue, 04 Sep 2001 10:18:51 +0000
Hi!
>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.
No, I tried that. The read()-Method stops the first time it encounters
chr(0), so when I try to upload my file like
TargetFolder.manage_addFile(NewDocumentName,open(DocumentPath,'r').read())
it will be only 6 bytes big.
Funny thing is, if I upload it from DTML, everything works fine and I get
the full 19K.
I copy the two pages again, that do the upload, because I have some
questions about them. Obviously, DoUpload receives a parameter "DateiName"
which is n o t a string, because it has an attribute ".filename". So my
general problem can be reduced to 2 questions:
1. what is the name of the class "DateiName" is an instance of?
2. How can I convert a string that denotes a path into an instance of this
class?
By the way: is there a run-time-type-identification in python (some function
that takes an object as arg and returns the name of its class)?
DTML-Document "index_html":
<html>
<form action="DoUpload" enctype="multipart/form-data" method="post">
<input type="file" name="DateiName">
<input type=submit value="upload"></td></tr>
</form>
</html>
DTML-Method "DoUpload":
<html>
<dtml-let fname="_.string.split(DateiName.filename,'\\')[-1]">
<dtml-with upload>
<dtml-if "_.has_key(fname)">
<dtml-call "_[fname].manage_upload(DateiName)">
<dtml-else>
<dtml-call "manage_addFile(fname,DateiName)">
</dtml-if>
<form action="upload/<dtml-var fname>" method="post">
<input type="submit" value="view">
</form>
</dtml-with>
</dtml-let>
</html>
_________________________________________________________________
Downloaden Sie MSN Explorer kostenlos unter http://explorer.msn.de/intl.asp