connection reset on file upload

3 views
Skip to first unread message

Clemens Hermann

unread,
Oct 12, 2007, 5:25:03 AM10/12/07
to pylons-discuss
Hi,

when using file uploads I get strange connection resets.
The affected form contains the following element:
<input name="data_file" type="file"/>

The controller handling the file looks like this:

class FileController(BaseController):
def read_file(self):
data_file = request.POST['data_file']
return "done"

so far everything works fine.

However, as soon as I remove the line "data_file =
request.POST['data_file']" I get
- "The connection was reset(Mozilla)"
- "The page cannot be displayed (IE)"

The problem only occurs If I try to upload a File with several
megabytes in size. Smaller files work out. Also if I do not select a
file for file upload, no error occurs. Anyway, as soon as I access
uploaded files in the controller, also large files work fine. There is
nothing reported in the shell running pylons.

Thanks in advance for any hints,

/ch

Garland, Ken R

unread,
Oct 12, 2007, 9:02:38 AM10/12/07
to pylons-...@googlegroups.com
I would recommend using fileapp to handle file uploads.

from paste import fileapp

Clemens Hermann

unread,
Oct 12, 2007, 12:06:03 PM10/12/07
to pylons-discuss
Ken,

thanks for your reply.

> I would recommend using fileapp to handle file uploads.

If I got the docs right, fileapp is intended to support sending file
content from the server to the browser. My problem is related to the
other direction (a user uploads a client-local file to the server via
the browser).

/ch

Garland, Ken R

unread,
Oct 12, 2007, 1:42:51 PM10/12/07
to pylons-...@googlegroups.com
My apologies, I didn't pay close attention to your issue. I have my
files stored outside of the project directory but I've pasted the
relevant parts that may help..

Just as example this is part of my uploading controller:

def upload(self, environ):
myfile = request.POST['myfile']
fileName = myfile.filename
myfile.file.close()

On 10/12/07, Clemens Hermann <clh...@googlemail.com> wrote:
>

Clemens Hermann

unread,
Oct 15, 2007, 5:26:22 AM10/15/07
to pylons-discuss
Ken,

thanks for your sample.

> def upload(self, environ):
> myfile = request.POST['myfile']
> fileName = myfile.filename
> myfile.file.close()

What happens if you do not use the provided data? It should be
technically possible to ignore the user supplied data completely. So
the application should at least continue to work if you modify the
controller as follows:

def upload(self, environ):
#myfile = request.POST['myfile']
#fileName = myfile.filename
#myfile.file.close()
pass

The temporary file should imho be deleted automatically without
explicit close() as soon as it is no longer referenced (it is a python
tempfile).
Does your app continue if you change it as above? Continue in this
context means: Do you also get one of the following messages?

- "The connection was reset(Mozilla)"
- "The page cannot be displayed (IE)"

regards,

/ch

Clemens Hermann

unread,
Oct 22, 2007, 9:56:26 AM10/22/07
to pylons-discuss
Finally I found the source of the problem.
In case of a file upload the responsible controller is called
immediately, even before the file is completely uploaded. The
execution of the controller instructions is stalled until the file is
uploaded completely if
- request.POST['data_file'] is accessed
- a template is rendered
If however a string response is sent via * return "this is my string
response" * no delay occurs. So in this case the controller sends a
response even before the browser has uploaded the file. This is the
reason for the "connection reset" message.

def upload(self, environ):
return "this is my string response"

reproduces the problem on a file upload form. As its is imho valid
controller code the error should not occur but the controller should
be stalled at/before the return statement.

regards,

/ch

Reply all
Reply to author
Forward
0 new messages