]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
toaster: open image files in binary mode when sending in response
authorElliot Smith <elliot.smith@intel.com>
Tue, 7 Jun 2016 15:37:29 +0000 (16:37 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 14 Jun 2016 10:08:58 +0000 (11:08 +0100)
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.

Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
lib/toaster/toastergui/views.py

index 9121ea90fd5c82ef74584544642cc7a1155331ed..5ceeb6be3ed53ed8d360fa8fa1d65db5566e8ee4 100755 (executable)
@@ -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)