From 0dee7f36409dfdbd9273d72d09ad30fa623c4378 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 8 Jul 2014 12:36:26 -0400 Subject: [PATCH] Make sure no file handler remain open --- mayan/apps/documents/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mayan/apps/documents/models.py b/mayan/apps/documents/models.py index b4cbc5e3ba..52fd1943a7 100644 --- a/mayan/apps/documents/models.py +++ b/mayan/apps/documents/models.py @@ -143,8 +143,11 @@ class Document(models.Model): logger.debug('file_path: %s' % file_path) if as_base64: + mimetype = get_mimetype(open(file_path, 'r'), file_path, mimetype_only=True)[0] image = open(file_path, 'r') - return u'data:%s;base64,%s' % (get_mimetype(open(file_path, 'r'), file_path, mimetype_only=True)[0], base64.b64encode(image.read())) + base64_data = base64.b64encode(image.read()) + image.close() + return u'data:%s;base64,%s' % (mimetype, base64_data) else: return file_path