diff options
| author | Sébastien Theys <seb@odoo.com> | 2019-05-20 14:12:38 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2019-05-21 11:37:20 +0000 |
| commit | 9dec7ba7e9edc905b121d2aa6f6d0922ef4121b3 (patch) | |
| tree | 7c715b1336c6f854372010d24647c67dedbb483d /addons/web/static/src/js/widgets | |
| parent | 923701851e61755a2d0a4df6121fe9b684e13df2 (diff) | |
[IMP] web, *: add utils to get dataURL (base64) from file/blob
* = partner_autocomplete, point_of_sale, web_editor,
website_forum, website_slides
This can be used for example to preview an image from a file input field.
It can also be used to send the base64 content of the input by RPC instead of
having to rely on form submit as POST with multipart/form-data.
Technically wrap FileReader.readAsDataURL in a Promise.
This will also be used in task-1930726
PR: #33508
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/widgets')
| -rw-r--r-- | addons/web/static/src/js/widgets/name_and_signature.js | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/addons/web/static/src/js/widgets/name_and_signature.js b/addons/web/static/src/js/widgets/name_and_signature.js index 7c3f05a7148..57a9a697494 100644 --- a/addons/web/static/src/js/widgets/name_and_signature.js +++ b/addons/web/static/src/js/widgets/name_and_signature.js @@ -2,6 +2,7 @@ odoo.define('web.name_and_signature', function (require) { 'use strict'; var core = require('web.core'); +var utils = require('web.utils'); var Widget = require('web.Widget'); var _t = core._t; @@ -597,11 +598,9 @@ var NameAndSignature = Widget.extend({ } this.$loadInvalid.addClass('d-none'); - var reader = new FileReader(); - reader.onload = function (ev) { - self._printImage(reader.result); - }; - reader.readAsDataURL(f); + utils.getDataURLFromFile(f).then(function (result) { + self._printImage(result); + }); }, /** * Handles input on name field: if the @see mode is 'auto', redraws the |
