Kirk Bailey
idiot1 at netzero.net
Thu Sep 18 12:11:42 EST 2003
My wiki, wikinehesa, has a upload in it. Try downloading it, and read the form in the footer of the page generated by wikinehesaed1.py, and read the script wikinehesaed2.py to see how the thing handles doing an upload. http://www.tinylist.org/ scan down to the OTHER STUFF section and there is the download for wikinehesa. To play with it, up by the top near the hit counter is a link to a working install of the wiki. David Fraser wrote: > Greenbeard wrote: > >> Does anyone have a good file upload example? >> When I try something like: >> def upload(req, file): >> tempFile = file.read() >> >> I get: AttributeError: File instance has no attribute >> 'read' >> >> if I use: >> >> tempFile = req.form['file'] I get the file contents but I don't >> think this would >> work well with large files (or would it?) >> Also, >> when I try to get attribues like file.type I get >> AttributeError: File instance has no attribute 'type'. >> I do get the file.filename. >> So how can I tell if it should be a binary write etc.? >> >> It looks like the publisher handler (which I am using) >> returns a File object but I can not get it to act like >> a file/StringIO object nor can I accesss the >> attributes that are mentioned in the documentation. >> >> I am using W2k, Python 2.2 and Mod_py 3.0.3. >> Thanks for the help, >> >> gb400 >> >> >> >> __________________________________ >> Do you Yahoo!? >> Yahoo! SiteBuilder - Free, easy-to-use web site design software >> http://sitebuilder.yahoo.com >> _______________________________________________ >> Mod_python mailing list >> Mod_python at modpython.org >> http://mailman.modpython.org/mailman/listinfo/mod_python >> >> >> > Don't know much about publisher, but a normal mod_python handler should > be able to do something like this (totally untested code): > > def handle(req): > argdict = util.FieldStorage(req) > for key in argdict.keys(): > value = argdict[key] > if type(value) == types.InstanceType: > if isinstance(value, util.StringField): > # this is for a normal field... > pass > elif isinstance(value, util.Field): > # this is for an attachment upload... > filename = field.filename > content_type = field.type > # this will work by doing a read... > contents = field.value > # or you can do the read yourself: > field.file.seek(0) > contents = field.file.read() > # reset the position so others can read it > field.file.seek(0) > > > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python > > -- -- end Cheers! Kirk D Bailey + think + http://www.howlermonkey.net +-----+ http://www.tinylist.org http://www.listville.net | BOX | http://www.sacredelectron.org Thou art free"-ERIS +-----+ 'Got a light?'-Prometheus + kniht + Fnord.
|