[mod_python] subscribe Uploading file troubles...

Clodoaldo clodoaldo.pinto.neto at gmail.com
Thu Nov 22 05:35:52 EST 2007


2007/11/21, Simon <simonrolin at gmail.com>:
>
>
> ---------- Forwarded message ----------
> From: Simon <simonrolin at gmail.com>
> Date: 22 nov. 2007 01:48
>  Subject: Re: [mod_python] subscribe Uploading file troubles...
> To: Graham Dumpleton <graham.dumpleton at gmail.com>
>
>
>
>
>  2007/11/21, Graham Dumpleton <graham.dumpleton at gmail.com>:
>
> > On 22/11/2007, Simon <simonrolin at gmail.com> wrote:
> > >
> > >
> > > ---------- Forwarded message ----------
> > > From: Simon < simonrolin at gmail.com>
> > > Date: 21 nov. 2007 20:39
> > >  Subject: Re: Mod_python Digest, Vol 56, Issue 21
> > > To: mod_python at modpython.org
> > >
> > > Hi all of you,
> > >
> > > I'm new to modpython and I'm actually facing some problem when trying to
> > > upload file.... I've read a lot but have not found any answer...
> > >
> > > Here is my HTML of my form:
> > > <form action=Upload2.py method=Post
> > > enctype="mutlipart/form-data">
> > >
> > > <input type=
> > > "file" name="file" value=""><
> > > div class="button"><input type=
> > > "submit" name="submit" value="Rechercher"
> > > class="submit" /></div></
> > > form>
> > >
> > > and here is Upload2 function:
> > >
> > > def Upload2(req):
> > >     timer = ExecTime()
> > >     _session(req)
> > >     myPage = page.Page(req,"Ajouter une photo")
> > >     fileitem = req.form['file']
> > >     myPage.add("Type is :" + str(type(fileitem)) + "<br />")
> >
> > A Python type string has <> characters in it. Parse it through
> > cgi.escape() so you can view the actual type string. Then repost
> > output as at the moment can't tell what the type is.
> >
> > Graham
>
>
> Graham, thanks for answering so fast....
>
>  So, fileitem or req.form['file'] is from type <class
> 'mod_python.util.StringField' >...
>  If I do the same with fileitem.file, i have : <type ' cStringIO.StringI'>
>
>  Any idea? Why does fileitem.filename is None?
>
>  Thanks a lot for your help, really great!

In a very fast test this is what I get for this code:

      message = 'fileitem: "%s" fileitem.file "%s"' % \
      (cgi.escape(str(fileitem)), cgi.escape(str(fileitem.file)))

fileitem: "Field('file',
'[settings]\nusername=Kakao\nteam=13802\nasknet=no\nmachineid=1\nlocal=162\n\n[http]\nactive=no\nhost=localhost\nport=8080\n\n')"
fileitem.file "<open file '<fdopen>', mode 'w+b' at 0xb7a95698>"


fileitem is of type Field as the manual says it should be. I'm leaving
to work now and i will try again to night.

Clodoaldo Pinto Neto


More information about the Mod_python mailing list