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:
@@ -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);
|
||||
};
|
||||
|
||||
}());
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
},
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user