From 3d2cae0896ee8026d1c2c5d31e4c4c8f74f2fef4 Mon Sep 17 00:00:00 2001 From: Collin Anderson Date: Sat, 3 Jan 2015 12:06:24 -0500 Subject: Fixed #24072 -- Added FileResponse for streaming binary files. --- docs/ref/request-response.txt | 18 ++++++++++++++++++ docs/releases/1.8.txt | 2 ++ 2 files changed, 20 insertions(+) (limited to 'docs') diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index 3f4d371df5..1375ba10e5 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -998,3 +998,21 @@ Attributes .. attribute:: StreamingHttpResponse.streaming This is always ``True``. + +FileResponse objects +==================== + +.. versionadded:: 1.8 + +.. class:: FileResponse + +:class:`FileResponse` is a subclass of :class:`StreamingHttpResponse` optimized +for binary files. It uses `wsgi.file_wrapper`_ if provided by the wsgi server, +otherwise it streams the file out in small chunks. + +.. _wsgi.file_wrapper: https://www.python.org/dev/peps/pep-3333/#optional-platform-specific-file-handling + +``FileResponse`` expects a file open in binary mode like so:: + + >>> from django.http import FileResponse + >>> response = FileResponse(open('myfile.png', 'rb')) diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index 12d0fbe69e..b69e69db49 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -559,6 +559,8 @@ Requests and Responses ` method allows setting a header unless it has already been set. +* You can use the new :class:`~django.http.FileResponse` to stream files. + * The :func:`~django.views.decorators.http.condition` decorator for conditional view processing now supports the ``If-unmodified-since`` header. -- cgit v1.3