On 6/28/09 10:20 PM, Annie wrote:
> I'm trying to this to work: users can download their files from their
> account page from a url like this:
> http://example.com/account/download/a1234565789asedga-2/
> for which django processes the authentication and then passes along
> the info to nginx to serve the file.
[...]
> Here are the relevant bits of code:
>
> # part of the views.py
>
> def download_file(request, dlkey=None, ftype=None):
> if request.user.is_authenticated():
> try:
> k = Ebook.objects.select_related().filter
> (ftype__exact=ftype).filter
> (book__orderdetail__dlkey__exact=dlkey).filter
> (book__orderdetail__medium__exact='E')[:1]
> for e in k:
> ebook = e.ebook
> filename = os.path.join(PROTECTED_DIR, os.path.basename
> (ebook))
> response = HttpResponse()
> response['X-Accel-Redirect'] = ebook
> response['Content-Disposition'] =
> "attachment;filename=" + ebook
> return response
> except Exception:
> raise Http404
>
>
> # part of the nginx configuration for the domain:
>
> location ^~ /account/download/ {
> include /etc/nginx/
> fastcgi_params_django;
> fastcgi_pass 127.0.0.1:1024;
> alias /home/me/web/example.com/
> public/media/books/;
> }
>
> location ^~ /media/books/ {
> root /home/me/web/example.com/
> public;
> internal;
> }
[...]
> [1] http://wiki.nginx.org/NginxXSendfile
I think the answer's in that document, actually. The value of
X-Accel-Redirect should be your internal location's URL
('/media/books/') plus your filename (os.path.basename(ebook), in your
view). Nginx will deliver
/home/me/web/example.com/public/media/books/ebook-basename.pdf.
John
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---