file upload

62 views
Skip to first unread message

Craig Swank

unread,
Feb 8, 2012, 3:03:04 PM2/8/12
to pylons-devel
Hello,
I just got wailed on by a file upload for about an hour. Does anyone
know why, when I post this form to my pyramid app:

<form action="${save_picture_url}" method="POST" enctype="multipart/
form-data">
<input type="file" name="profile_picture" value=""/><br/>
<input type="hidden" name="csrf_token" value="${csrf_token}"/>
<input type="submit" value="save picture"/>
</form>

the request.POST['profile_picture'] is an empty string. When I move
the position of the csrf_token field like this:

<form action="${save_picture_url}" method="POST" enctype="multipart/
form-data">
<input type="hidden" name="csrf_token" value="${csrf_token}"/>
<input type="file" name="profile_picture" value=""/><br/>
<input type="submit" value="save picture"/>
</form>

Then request.POST['profile_picture'] is a FieldStorage object as
expected.

Craig

Craig Swank

unread,
Feb 8, 2012, 3:15:15 PM2/8/12
to pylons-devel
Forgot to add environment info
pyramid: 1.3a6
python: 2.7
os: ubuntu on a vagrant VM on a mac.

Chris McDonough

unread,
Feb 8, 2012, 3:22:46 PM2/8/12
to pylons...@googlegroups.com
Can't replicate. This app tries to do so but using either "/broken" or
"/works", it returns the same result (a repr of the FieldStorage) on
Pyramid 1.3a7:

from waitress import serve
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.view import view_config

@view_config(name='works')
def works(request):
form = """
<html>
<form action="/works" method="POST" enctype="multipart/form-data">
<input type="hidden" name="csrf_token" value="token"/>


<input type="file" name="profile_picture" value=""/><br/>
<input type="submit" value="save picture"/>
</form>

</html>
"""
if request.method == 'GET':
return Response(form, content_type='text/html')
else:
picture = repr(request.POST['profile_picture'])
return Response(picture, content_type='text/plain')

@view_config(name='broken')
def broken(request):
form = """
<html>
<form action="/broken" method="POST" enctype="multipart/form-data">


<input type="file" name="profile_picture" value=""/><br/>

<input type="hidden" name="csrf_token" value="token"/>


<input type="submit" value="save picture"/>
</form>

</html>
"""
if request.method == 'GET':
return Response(form, content_type='text/html')
else:
picture = repr(request.POST['profile_picture'])
return Response(picture, content_type='text/plain')

if __name__ == '__main__':
config = Configurator()
config.scan('__main__')
serve(config.make_wsgi_app())

Craig Swank

unread,
Feb 8, 2012, 3:32:33 PM2/8/12
to pylons-devel
Your app also works in my VM. Both views show a FieldStorage object
for POST['profile_picture']

Hmm, confused. One difference I can see between the two is you use
waitress to serve it, I'm using pserve. I've not heard of waitress
until now. Is there a possibility that pserve could be the reason I'm
having problems?

Craig

Craig Swank

unread,
Feb 8, 2012, 3:40:49 PM2/8/12
to pylons-devel
I made an app with pcreate -t starter and pasted your app's view stuff
in and it worked there as well, started it with pserve and both
uploads worked there as well.

Chris McDonough

unread,
Feb 8, 2012, 5:48:30 PM2/8/12
to pylons...@googlegroups.com
On Wed, 2012-02-08 at 12:40 -0800, Craig Swank wrote:
> I made an app with pcreate -t starter and pasted your app's view stuff
> in and it worked there as well, started it with pserve and both
> uploads worked there as well.
>
>
> On Feb 8, 1:32 pm, Craig Swank <craigsw...@gmail.com> wrote:
> > Your app also works in my VM. Both views show a FieldStorage object
> > for POST['profile_picture']
> >
> > Hmm, confused. One difference I can see between the two is you use
> > waitress to serve it, I'm using pserve. I've not heard of waitress
> > until now. Is there a possibility that pserve could be the reason I'm
> > having problems?

"pserve" is just a wrapper script; the actual server being run depends
the [server] section in your configuration file.

- C


Reply all
Reply to author
Forward
0 new messages