Hi,

I'm new to Werkzeug (trying to move many scripts from mod_python to
WSGI), and still trying to get it all in my head, but enjoying it very
much.  Playing with multipart/form-data forms for file uploads,  I see
that
    stream, form, files = parse_form_data(environ)

returns different values for 'form' and 'files' based on the data type
(plain text vs non-plain-text???) and browser used to fill the form
(Firefox, IE8, Chrome).
I'm using werkzeug 0.5.1 and mod_wsgi 2.3 (Apache 2.2.11) and a very
simple form:

 <html><head><title>Form example</title> </head><html>
 <form action='http://localhost/processform.wsgi' enctype='multipart/
form-data'  method ='POST'>
 <table>
    <tr><td>Email:</td><td><input name='emailaddress' type=text
size=50></td></tr>
    <tr><td>Name: </td><td><input name='name'         type=text
size=50></td></tr>
    <tr><td>File: </td><td><input name ='attachfile'  type=file
size=50></td></tr>
 </table><input type=submit value='submit'> </body></html>

and a very simple WSGI processform.wsgi script:

#!/usr/bin/python
from werkzeug.utils import parse_form_data
def show_obj(o):
    return "%s" % (str(o).replace('<','&lt;'))

def application(environ, start_response):
    start_response('200 OK', [('Content-type', 'text/html')])
    stream, form, files = parse_form_data(environ)
    return ['<html><head><title>Form Results</title></head><body>',
            'Stream:: %s<br>' % show_obj(stream),
            'Form::   %s<br>' % show_obj(form),
            'Files::  %s<br>' % show_obj(files),
            '</body></html>']
#end

With a small, plain text file sent from Firefox 3.5.2 or IE8,
parse_data_form(environ) puts the uploaded file object in a
FileStorage object in the 'files' output:

  Stream:: <cStringIO.StringI object at 0x8b2cef0>
  Form:: MultiDict([('emailaddress', u''), ('name', u'')])
  Files:: MultiDict([('attachfile', <FileStorage:
u'Test.dat' ('application/octet-stream')>)])

while with the same datafile sent from Chrome (2.0.172.39),
parse_data_form(environ) puts the contents of this file into the
'attachfile' member of the 'form' output:

  Stream:: <cStringIO.StringI object at 0x8b2ce18>
  Form:: MultiDict([('attachfile', u'contents of Test.dat\r\n'),
('emailaddress', u''), ('name', u'')])
  Files:: MultiDict([])

If I use a file that is not "plain-text", the file object goes into
the 'files' output, just as when using Firefox.
The size of the plain text file (I've tried sizes from 100 bytes up to
~15Mb) does not seem to matter, but some plain text files seem to be
put into the files output.  It does seem that files with Windows line
endings (CRLF) are more likely to be placed in the form MultiDict
instead of the files MultiDict.

FWIW, I get the "expected, uniform" behavior (in which uploaded data
files go into a FileStorage object regardless of data content or
browser) with mod_python.

I haven't dug very deep into this, but
werkzeug.http.parse_multipart_headers(), is definitely returning
different results for 'form' and 'file'.       The headers returned by
parse_multipart_headers() for data sent by Chrome definitely always
have 'Content-Disposition', but do not always have a 'Content-
Type'.....   which appears to lead to the problem.   It also appears
that the Content-length is somewhat shorter using Chrome than other
browsers.

At that point, I'm not sure if this is a WSGI or a Werkzeug problem.
Any suggestions for what might be going wrong or how this feature can
be worked-around would be greatly appreciated.

Thanks in advance,

--Matt Newville

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to