I do not understand exactly why you are doing it like this. Do you want to store the base 64 encoded string as a FileDocument / Image? If so, you should do it not with an input string for a microflow, but with:
mx.data.saveDocument(this.fileGuid, fileName + ".jpg", { width: 180, height: 180 }, fileBlob, lang.hitch(this,function() {
// success: if file document is saved succesfully, also call additional microflow if configured
if (this.microflow){
this._execMicroflow();
}
}), lang.hitch(this,function(e) {
mx.ui.info(this.id + ": Error occurred attempting to save document: " + e);
}));
The base64 encoded image you can convert to an image with JS with:
var fileBlob = this._b64toBlob(dataUrl.replace("data:image/png;base64,", ""), "image/jpeg");
_b64toBlob : function(b64Data, contentType, sliceSize) {
contentType = contentType || '';
sliceSize = sliceSize || 512;
var byteCharacters = atob(b64Data);
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
var blob = new Blob(byteArrays, {type: contentType});
return blob;
}
Does this help?
Also; please state the Mendix version you are using; the Client API has different functions per version, so could very well be that you / me are referring to changed functions...
is this the same as:
https://forum.mendix.com/link/questions/88255
you may find solution there.
Hello Ivo Sturm, I am trying integrating a signature device to mendix application with javascript API, I am calling the javascript by a widget from app store "JavaScriptButton" which is assigning the SRC to IMG inside HTMLSnippetWithContext widget which i got from Appstore.
The Function from API is as :
function generateImage() {
signatureImage = document.getElementById("signatureImage");
var signatureCanvas = document.createElement("canvas");
signatureCanvas.id = "signatureCanvas";
signatureCanvas.height = signatureImage.height;
signatureCanvas.width = signatureImage.width;
var signatureCtx = signatureCanvas.getContext("2d");
clearCanvas(signatureCanvas, signatureCtx);
signatureCtx.lineWidth = 1;
signatureCtx.strokeStyle = 'blue';
lastPoint = { "x": 0, "y": 0 };
isDown = false;
for (var i = 0; i < m_penData.length; i++) {
processPoint(m_penData[i], signatureCanvas, signatureCtx);
}
signatureImage.src = signatureCanvas.toDataURL("image/jpeg");
var ImageCode = signatureCanvas.toDataURL("image/jpeg");
return ImageCode;
}
In 'ImageCode' i have string / data as 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0CAYAAADL1t+KAAAgAElEQVR4Xu2dXaytWVpW5.........' data. I need to save in entity with reference to other field value inside mendix application page. so that later i can retrieve the image.
So, I found some code to return this value to microflow and then from microflow save to entity (as I tried in METHOD 1). But getting empty data in microflow.
I am new to mendix development, Can you please provide the relation between my function generateImage() above and how I can implement your suggested code? I am using 6.10.2 modeler.
I am waiting for you kind reply.. thank you in advance...