Set type to Blob for SVG image

Without proper type, browsers do not render SVG image from Blob.
So we try to guess if it is an SVG image by trying to parse it as XML.
For other types, browsers render them without type.

Closes #12201
This commit is contained in:
Cédric Krier
2023-04-30 00:57:46 +02:00
parent c30868d091
commit ff17338ea5
3 changed files with 21 additions and 16 deletions
+19
View File
@@ -4244,4 +4244,23 @@
return el.html();
};
Sao.common.image_url = function(data) {
if (!data) {
return null;
}
var type = '';
try {
var xml = data;
if (xml instanceof Uint8Array) {
xml = new TextDecoder().decode(data);
}
if (jQuery.parseXML(xml)) {
type = 'image/svg+xml';
}
} catch (e) {
}
blob = new Blob([data], {type: type});
return window.URL.createObjectURL(blob);
};
}());
+1 -8
View File
@@ -4392,17 +4392,10 @@ function eval_pyson(value){
value = jQuery.when(null);
}
value.done(data => {
var url, blob;
if (record !== this.record) {
return;
}
if (!data) {
url = null;
} else {
blob = new Blob([data]);
url = window.URL.createObjectURL(blob);
}
this.image.attr('src', url);
this.image.attr('src', Sao.common.image_url(data));
this.update_buttons(Boolean(data));
});
},
+1 -8
View File
@@ -2844,14 +2844,7 @@
}
const render = () => {
const set_src = data => {
var img_url, blob;
if (!data) {
img_url = null;
} else {
blob = new Blob([data]);
img_url = window.URL.createObjectURL(blob);
}
cell.attr('src', img_url);
cell.attr('src', Sao.common.image_url(data));
};
var value = this.field.get_client(record);