On 8 jan, 00:15, bruno desthuilliers <bruno.desthuilli...@gmail.com>
wrote:
> On 7 jan, 23:37, David Lindquist <david.lindqu...@gmail.com> wrote:
>
> > I would like to return a binary file from a view, and so far I have
> > something like this:
>
> > def my_file(request):
> > file_data = open("/path/to/file", "rb").read()
> > response = HttpResponse(file_data, mimetype="application/
> > whatever")
> > response['Content-Disposition'] = 'attachment; filename=my_file'
> > return response
>
> > Is there a better way to do this, especially for very large (> 10MB)
> > files?
>
> Do you have any reason to serve these files thru django instead of
> letting your frontal web server handle them ?.
(sorry, hit the send button to soon)
Else, you could eventually just pass the file object itself to
HttpResponse:
http://docs.djangoproject.com/en/dev/ref/request-response/#passing-iterators
... but I don't know if you will gain that much from doing so (wild
guess: this probably depends on how you deploy your django instance).
Also, this may (or not) cause problem with ressource (the file)
deallocation (but this can eventually be solved using some 'lazy'
proxy instead of the file object itself).
HTH
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@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=en
-~----------~----~----~----~------~----~------~--~---