From 556cef1ba8facbd3231f6351956a6581c6367632 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 17 Aug 2019 09:20:36 +0200 Subject: [PATCH] [2.2.x] Fixed #30694 -- Documented FileResponse does not seek its file source. Backport of 7203efb799969b4662ecb58f4cefd2a5f2e0062b from master --- docs/howto/outputting-pdf.txt | 1 + docs/ref/request-response.txt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/docs/howto/outputting-pdf.txt b/docs/howto/outputting-pdf.txt index 9950c4316c..986a5b252c 100644 --- a/docs/howto/outputting-pdf.txt +++ b/docs/howto/outputting-pdf.txt @@ -67,6 +67,7 @@ Here's a "Hello World" example:: # FileResponse sets the Content-Disposition header so that browsers # present the option to save the file. + buffer.seek(0) return FileResponse(buffer, as_attachment=True, filename='hello.pdf') The code and comments should be self-explanatory, but a few things deserve a diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index 22cc016057..30ad0ccf42 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -1106,6 +1106,8 @@ Attributes If ``open_file`` doesn't have a name or if the name of ``open_file`` isn't appropriate, provide a custom file name using the ``filename`` parameter. + Note that if you pass a file-like object like ``io.BytesIO``, it's your + task to ``seek()`` it before passing it to ``FileResponse``. The ``Content-Length``, ``Content-Type``, and ``Content-Disposition`` headers are automatically set when they can be guessed from contents of