Hi Marco
I hope this help you out. Please not this code is untested and will probably not work on Native platform
Cheers, Andries
function toDataUrl(url) {
return new Promise(resolve => {
const xhr = new XMLHttpRequest();
xhr.onload = () => {
const reader = new FileReader();
reader.onloadend = () => {
resolve(reader.result);
};
reader.readAsDataURL(xhr.response);
};
xhr.open("GET", url);
xhr.responseType = "blob";
xhr.send();
});
}
// END EXTRA CODE
/**
* @param {MxObject} imageDocument
* @returns {Promise.<string>}
*/
export async function ImageToBase64String(imageDocument) {
// BEGIN USER CODE
// TODO make it Native, implement error cases
const url = mx.data.getDocumentUrl(imageDocument.getGuid(), imageDocument.get("changeDate"));
return toDataUrl(url);
// END USER CODE
}