使用django + nginx + apache mod_wsgi访问正在进行的上传文件

时间:2022-09-17 07:56:48

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.

我知道当我们上传到使用django的web应用程序时,我们无法在服务器完全接收之前访问上传文件。

So my question, is there any way to check/access the total byte of upload file in progress?

所以我的问题是,有没有办法检查/访问正在进行的上传文件的总字节数?

thanks

4 个解决方案

#1


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上传处理程序来监视正在进行的上载。您需要做的就是继承django.core.files.uploadhandler.FileUploadHandler并实现receive_data_chunk和file_complete方法。

Django's upload handler documentation gives you the details you need.

Django的上传处理程序文档为您提供所需的详细信息。

#2


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.

这取决于您的服务器设置。如果你将Apache与mod_python一起使用,那么文件会在到达时流式传输到你的Django进程。但是如果你使用wsgi或fastcgi在web服务器后面运行Django,那么在django介入之前服务器将缓冲整个文件。那么上面给出的解决方案就不行了。

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:ModUploadProgress for Lighttpd, which implements the upload_progress view for you on the server. Or http://wiki.nginx.org/NginxHttpUploadProgressModule for nginx.

这是“按设计”,因为绑定等待文件上传的fastcgi进程将是一个很大的浪费。因此,您需要做的是使用服务器模块,例如http://redmine.lighttpd.net/wiki/1/Docs:ModUploadProgress for Lighttpd,它在服务器上为您实现upload_progress视图。或者http://wiki.nginx.org/NginxHttpUploadProgressModule用于nginx。

#3


Check AJAX upload progress bars with jQuery, Django and nginx

使用jQuery,Django和nginx检查AJAX上传进度条

#4


Just found an upload progress module for apache:

刚刚找到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.

我不知道的是它是如何(或是否)与django和mod_wsgi一起使用的。

#1


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上传处理程序来监视正在进行的上载。您需要做的就是继承django.core.files.uploadhandler.FileUploadHandler并实现receive_data_chunk和file_complete方法。

Django's upload handler documentation gives you the details you need.

Django的上传处理程序文档为您提供所需的详细信息。

#2


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.

这取决于您的服务器设置。如果你将Apache与mod_python一起使用,那么文件会在到达时流式传输到你的Django进程。但是如果你使用wsgi或fastcgi在web服务器后面运行Django,那么在django介入之前服务器将缓冲整个文件。那么上面给出的解决方案就不行了。

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:ModUploadProgress for Lighttpd, which implements the upload_progress view for you on the server. Or http://wiki.nginx.org/NginxHttpUploadProgressModule for nginx.

这是“按设计”,因为绑定等待文件上传的fastcgi进程将是一个很大的浪费。因此,您需要做的是使用服务器模块,例如http://redmine.lighttpd.net/wiki/1/Docs:ModUploadProgress for Lighttpd,它在服务器上为您实现upload_progress视图。或者http://wiki.nginx.org/NginxHttpUploadProgressModule用于nginx。

#3


Check AJAX upload progress bars with jQuery, Django and nginx

使用jQuery,Django和nginx检查AJAX上传进度条

#4


Just found an upload progress module for apache:

刚刚找到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.

我不知道的是它是如何(或是否)与django和mod_wsgi一起使用的。