diff options
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/controllers/main.py | 8 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 9 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/kanban/kanban_record.js | 9 |
3 files changed, 22 insertions, 4 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index c2027984c42..ed2e9f13062 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -37,6 +37,7 @@ import odoo.modules.registry from odoo.api import call_kw, Environment from odoo.modules import get_resource_path from odoo.tools import crop_image, topological_sort, html_escape, pycompat +from odoo.tools.mimetypes import guess_mimetype from odoo.tools.translate import _ from odoo.tools.misc import str2bool, xlwt, file_open from odoo.tools.safe_eval import safe_eval @@ -1218,8 +1219,11 @@ class Binary(http.Controller): if row and row[0]: image_base64 = base64.b64decode(row[0]) image_data = io.BytesIO(image_base64) - imgext = '.' + (imghdr.what(None, h=image_base64) or 'png') - response = http.send_file(image_data, filename=imgname + imgext, mtime=row[1]) + mimetype = guess_mimetype(image_base64, default='image/png') + imgext = '.' + mimetype.split('/')[1] + if imgext == '.svg+xml': + imgext = '.svg' + response = http.send_file(image_data, filename=imgname + imgext, mimetype=mimetype, mtime=row[1]) else: response = http.send_file(placeholder('nologo.png')) except Exception: diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 0c28f0f4b61..12b7b8f302c 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1471,12 +1471,19 @@ var FieldBinaryImage = AbstractFieldBinary.extend({ }, }), supportedFieldTypes: ['binary'], + file_type_magic_word: { + '/': 'jpg', + 'R': 'gif', + 'i': 'png', + 'P': 'svg+xml', + }, _render: function () { var self = this; var url = this.placeholder; if (this.value) { if (!utils.is_bin_size(this.value)) { - url = 'data:image/png;base64,' + this.value; + // Use magic-word technique for detecting image type + url = 'data:image/' + (this.file_type_magic_word[this.value[0]] || 'png') + ';base64,' + this.value; } else { url = session.url('/web/image', { model: this.model, diff --git a/addons/web/static/src/js/views/kanban/kanban_record.js b/addons/web/static/src/js/views/kanban/kanban_record.js index 9be296e3e31..7013464ea87 100644 --- a/addons/web/static/src/js/views/kanban/kanban_record.js +++ b/addons/web/static/src/js/views/kanban/kanban_record.js @@ -166,6 +166,12 @@ var KanbanRecord = Widget.extend({ var colorID = this._getColorID(variable); return KANBAN_RECORD_COLORS[colorID]; }, + file_type_magic_word: { + '/': 'jpg', + 'R': 'gif', + 'i': 'png', + 'P': 'svg+xml', + }, /** * @private * @param {string} model the name of the model @@ -179,7 +185,8 @@ var KanbanRecord = Widget.extend({ options = options || {}; var url; if (this.record[field] && this.record[field].value && !utils.is_bin_size(this.record[field].value)) { - url = 'data:image/png;base64,' + this.record[field].value; + // Use magic-word technique for detecting image type + url = 'data:image/' + this.file_type_magic_word[this.record[field].value[0]] + ';base64,' + this.record[field].value; } else if (this.record[field] && ! this.record[field].value) { url = "/web/static/src/img/placeholder.png"; } else { |
