I know that when we upload to a web application which use django, we couldn't access the upload file before it completely receive by the server.
So my question, is there any way to check/access the total byte of upload file in progress?
thanks
I know that when we upload to a web application which use django, we couldn't access the upload file before it completely receive by the server.
So my question, is there any way to check/access the total byte of upload file in progress?
thanks
You can monitor an upload in progress by writing your own Django upload handler. All you need to do is subclass django.core.files.uploadhandler.FileUploadHandler
and implement the receive_data_chunk
and file_complete
methods.
Django's upload handler documentation gives you the details you need.
It depends on your server setup. If you use Apache with mod_python then files are streamed to your Django process as they arrive. But if you run Django behind a web server using wsgi or fastcgi, then the whole file will be buffered by the server before django gets involved. Then the solution given above wont work.
This is "by design" because tying up fastcgi processes waiting for file uploads would be a big waste. So what you have to do instead is use a server module such as http://redmine.lighttpd.net/wiki/1/Docs%3AModUploadProgress for Lighttpd, which implements the upload_progress view for you on the server. Or http://wiki.nginx.org/NginxHttpUploadProgressModule for nginx.
Just found an upload progress module for apache:
http://github.com/drogus/apache-upload-progress-module
What I don't know is how (or whether) it's works with django & mod_wsgi.