views:

497

answers:

3

Hi All,
I've got a Django app that accepts uploads from jQuery uploadify, a jQ plugin that uses flash to upload files and give a progress bar.

Files under about 150k work, but bigger files always fail and almost always at around 192k (that's 3 chunks) completed, sometimes at around 160k. The Exception I get is below.

exceptions.IOError
request data read error
File "/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py", line 171, in _get_post
    self._load_post_and_files()
File "/usr/lib/python2.4/site-packages/django/core/handlers/wsgi.py", line 137, in _load_post_and_files
    self._post, self._files = self.parse_file_upload(self.META,     self.environ[\'wsgi.input\'])
File "/usr/lib/python2.4/site-packages/django/http/__init__.py", line 124, in parse_file_upload
    return parser.parse()
File "/usr/lib/python2.4/site-packages/django/http/multipartparser.py", line 192, in parse
    for chunk in field_stream:
File "/usr/lib/python2.4/site-packages/django/http/multipartparser.py", line 314, in next
    output = self._producer.next()
File "/usr/lib/python2.4/site-packages/django/http/multipartparser.py", line 468, in next
    for bytes in stream:
File "/usr/lib/python2.4/site-packages/django/http/multipartparser.py", line 314, in next
    output = self._producer.next()
File "/usr/lib/python2.4/site-packages/django/http/multipartparser.py", line 375, in next
    data = self.flo.read(self.chunk_size)
File "/usr/lib/python2.4/site-packages/django/http/multipartparser.py", line 405, in read
    return self._file.read(num_bytes)

When running locally on the Django development server, big files work.
I've tried setting my FILE_UPLOAD_HANDLERS = ("django.core.files.uploadhandler.TemporaryFileUploadHandler",) in case it was the memory upload handler, but it made no difference.

Does anyone know how to fix this?

+1  A: 

The problem could be:

  • your internet connection (some firewall blocking large uploads, just try uploading to some other service to test that).
  • your webbrowser (try disabling flash to see if that works)
  • your webserver (perhaps your webserver prohibits large uploads?)

So... to be a bit more helpful you'll have to give us some info about which part is the problem (should be fairly easy to test) and if it's the webserver (which I'm guessing) what kind of webserver you're running, what kind of Python handler (mod_wsgi, mod_python, fastcgi, etc..)

WoLpH
Just tested uploading a large file on another site with no problem. I'm running python 2.4, django 1.1, mod_wsgi. I'll try to test uploading without the flash uploader now.
Jake
I can upload to a different Django project on the same server using the Django admin interface (normal form file field). So perhaps it's a flash or uplodify issue, I don't know where to start to work that out.
Jake
Another update, I created a form posting to the same place as uploadify did, and I get the same error. So... Not my browser or internet connection, not my server, not uploadify. The main difference I can see between the project that works and the one that doesn't is that one uses django admin interface to upload to a models file field, and the broken one just puts downloads in a folder. But the error I have is a read error.
Jake
The "read error" means that the server has lost the connection to the client for some reason. So... during the upload the connection was somehow broken and the server can't read new data from the client anymore. I'm at a loss to explain it though, if it's not working with the normal upload form either... What browser, server and Python handler are you running? I'm guessing some bug in your webserver/webbrowser is biting you.
WoLpH
I was using FF3/windows. In Chrome/windows it gets to a higher percentage before failing. In FF3/mac it works! I'm not sure what you mean by Python Handler, is that mod_wsgi/apache? I'm running centOS on a media temple DV server (python 2.4, django 1.1)
Jake
Yes, that's what I meant :)THere are several reports of uploading failing in certain situations with Django: http://stackoverflow.com/questions/411902/django-file-upload-failing-occasionally http://www.pubbs.net/200909/django/82114-ioerror-request-data-read-error-on-post-anyone-solved-this.html http://groups.google.com/group/django-users/msg/c625a04cb3bf9a8aSome say it's keep-alives in combination with Safari others have different opinions. But I don't see a real solution.
WoLpH
+1  A: 

I'm currently having the same issue. But for much larger files. Running Django 1.1.1, mod_wsgi 2.6 (prefork MPM) and apache 2.2 all on Ubuntu. On the front end I'm seeing a timeout somewhere between 15 and 30 min (uploading files over 100MB). I've seen consistent failures almost every time on IE7 and IE8. Only failed once on FF. But FF survived a 250MB upload well over 15 min. In my apache logs I'm seeing the same "IOError: request data read error". I had a thread for this, but I killed it in favor of this fresher one with more activity. (Sorry this is posted as an answer, can't leave comments).

CrashRoX
I'm currently rewriting my uploader. I'm creating a Django model with a file field rather than handling the storage myself. I noticed that I could upload large files with another system using this method. I'll keep you posted on how it goes.
Jake
I'm using a custom file handler with a file field and a backend store on S3.
CrashRoX
Are you using daemon mode of mod_wsgi? If you are, you would see a read error like that if Apache for some reason decided to kill of its Apache server child process which is proxying to mod_wsgi daemon process. Apache shouldn't do this though as it should know process is still busy.
Graham Dumpleton
I am running in daemon mode. Is there a mod_wsgi timeout of some sort that kills the process? Do you think threaded mode may have any affect?I have uploaded multiple success large items from FF3 on Mac. Failed almost every time (but one) on IE7/8 on Win. Going to test FF3 win shortly. A user reported failures on Safari and Chrome on files 150mb and 250mb in size. Everything I have been testing with has been at least 100mb and takes 15+ minutes.
CrashRoX
If it is working for some browsers, then likely not an issue with Apache server processes being killed, which as I said Apache shouldn't be killing. Nothing to do with mod_wsgi as mod_wsgi doesn't kill off the normal Apache server child processes, Apache itself controls that.
Graham Dumpleton
Anything you recommend trying on the Apache side? Maybe the browsers expect a keep-alive or some other setting... I'm not satisfied with marking this up as a global browser problem. It seems to big a problem for that.
CrashRoX
I uploaded two 250mb file on FF3 win that took about 45 min each and both had no issues...
CrashRoX
+1  A: 

This is common with MediaTemple -- I encountered this problem, fixed it, and somehow it's broken again. It has to deal with something about NFS locking, and the system calls used by django's storage modules.

... (10 minutes later) ...

Found it:

Anyone trying to run the latest 1.1 svn release will have noticed that the above fix no longer works since TemporaryFileUploaderHandler now uses the locking code also. A workaround until mediatemple and/or django devs figure this out is to edit django.core.files.locks and change the two calls to fcntl.lockf to fcntl.flock

Here's a relevant bug report for anyone who's interested: http://code.djangoproject.com/ticket/9400

http://osdir.com/ml/DjangoUsers/2009-06/msg01014.html -> https://forums.mediatemple.net/viewtopic.php?id=2514

Marcel Chastain