1. You could read (and thus write) in smaller chunks, by giving read() an argument indicating the number of bytes to read:
f = open(file) # The mode 'r' is default for buf in read(1024*32): response.write(buf) f.close() 2. You could, instead, let Apache serve the files in encrypted form, and sell the user a decryption key. On Mon, Nov 23, 2009 at 12:18 PM, 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=. > > > -- 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=.