[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>
This commit is contained in:
@@ -1465,13 +1465,10 @@ var AbstractFieldBinary = AbstractField.extend({
|
||||
this.do_warn(_t("File upload"), _.str.sprintf(msg, utils.human_size(this.max_upload_size)));
|
||||
return false;
|
||||
}
|
||||
var filereader = new FileReader();
|
||||
filereader.readAsDataURL(file);
|
||||
filereader.onloadend = function (upload) {
|
||||
var data = upload.target.result;
|
||||
utils.getDataURLFromFile(file).then(function (data) {
|
||||
data = data.split(',')[1];
|
||||
self.on_file_uploaded(file.size, file.name, file.type, data);
|
||||
};
|
||||
});
|
||||
} else {
|
||||
this.$('form.o_form_binary_form').submit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user