bitbake: toaster: open image files in binary mode when sending in response

The view code for downloading image files used the "r" flag
to read the file, then used the open file object to form the
HTTP response.

While this worked in Python 2, Python 3 appears to be more strict
about this sort of thing, and Django throws a UnicodeDecodeError
when a file opened this way is used in a response.

Open the file with the "b" flag (binary mode) so that Django can
correctly convert the binary file handle to an HTTP response.

(Bitbake rev: c4d67968d0ec1d5ff53cdc0dccf6a7869c89597b)

Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Elliot Smith 2016-06-07 16:37:29 +01:00 committed by Richard Purdie
parent 16df75d49d
commit eba5321786
1 changed files with 1 additions and 1 deletions

View File

@ -2338,7 +2338,7 @@ if True:
)
if file_name and response_file_name:
fsock = open(file_name, "r")
fsock = open(file_name, "rb")
content_type = MimeTypeFinder.get_mimetype(file_name)
response = HttpResponse(fsock, content_type = content_type)