You may try this
async function base64ToImageNative(base64String) {
// Decode the Base64 string to binary data
const binaryString = atob(base64String.split(',')[1]);
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
// Convert Uint8Array
const file = new Blob([bytes], { type: 'image/png' }); // Adjust the MIME type as necessary
// Use the Mendix client API
const mxObject = await mx.data.create({
entity: "System.FileDocument",
callback: obj => {
console.log("Mendix object created", obj);
},
error: e => {
console.error("Error creating Mendix object", e);
}
});
// Set the name and mime type
mxObject.set("Name", "ImageFileName.png");
mxObject.set("MimeType", "image/png");
// Save the file document
return new Promise((resolve, reject) => {
mx.data.saveDocument(mxObject.getGuid(), "ImageFileName.png", {}, file, () => {
console.log("File saved successfully.");
resolve(mxObject);
}, (error) => {
console.error("Error saving file: ", error);
reject(error);
});
});
}