Hi Adrian, if you use Apache, you can use mod_xsendfile[1] (other servers have similar functionalities). Then you write somethink like this in your view:
import mimetypes [...] mimetype, encoding = mimetypes.guess_type(path) response = HttpResponse("", content_type=mimetype) response['X-Sendfile'] = absolute_path_to_file response['Content-Disposition'] = 'attachment; file=%s' % os.path.split(path)[-1] return response Apache will see the X-Sendfile header and handle the rest for you. If this is a high volume site, you'd probably better use a lightweight reverse proxy like nginx[1], [2]. Regards, Benjamin [1] http://wiki.nginx.org/Main [2] http://wiki.nginx.org/NginxXSendfile On 23 Nov., 18:18, Adrián Ribao <ari...@gmail.com> wrote: > Hello, > > I have created a website where you can buy and download some files. > For security reasons all the files are served through a view, where > comprobations are made in order to assure that the user bought the > product. > > The problem is that the files are at least 400Mb and some of them are > nearly 1Gb. Using this view is inefficient since all the content is > loaded into memory and it kills the server: > > type, encoding = mimetypes.guess_type(file) > name = os.path.basename(file) > response = HttpResponse(mimetype=type) > response['Content-Disposition'] = 'attachment; filename=%s' % > (smart_str(name),) > > f = open(file, 'r') > response.write(f.read()) > f.close() > return response > > How could I solve this problem? > > Regards, > > Adrian. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=.