346
Views
8
Comments
Solved
convert base64ToBinary to open in browser
Question
Application Type
Reactive
I want to open a Base64 document in a new tab maybe using javascript

2026-03-16 00-00-40
Palak Patel
Solution

Dear Fabiano,
Greetings of the day

We had exactly same situation few days back and we found 2 ways to achieve that in Mobile App:
1) Using JavaScript
- > you can open binary directly in JavaScript using following command:
-------------------------------------------------------------------------------------------------------------
window.open("data:"+mimetype+";base64,"+$parameters.BinaryData, "_blank");
-------------------------------------------------------------------------------------------------------------
(here
BinaryData is input parameter with datatype as Binary Data
MimeType
we are using as application/pdf or image/jpeg. You can use as per your document type

)

2) Using FilePlugin
-> This plugin handles mostly all mimetype and you just need to input BinaryData/FileName/MimeType.
-> But you need to first save the document and then open it using your saved locaction URI or URL.


Hope I am clear to explain you the scenarios which can help to solve your development.

Thanks & Regards,
Palak Patel

UserImage.jpg
Fabiano Ferreira
achieve using the java script I found this format that met well. Thanks!


/*jshint esversion: 6 */
// --- Bibliotecas utilizadas
/*
CryptoJS v3.1.2
code.google.com/p/crypto-js
(c) 2009-2013 by Jeff Mott. All rights reserved.
code.google.com/p/crypto-js/wiki/License
*/
var pdfWindow = window.open("");
pdfWindow.document.write(
    "<iframe width='100%' height='100%' src='data:application/pdf;base64, " +
    encodeURI($parameters.input) + "'></iframe>"
);
2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi Fabiano,

A browser will most likely require the base64 string not a binary. 

What type of documents do you want to show?

For many document types of the OutSystems Forge you find components that can do that like:

https://www.outsystems.com/forge/component-overview/10147/html-document-viewer 

https://www.outsystems.com/forge/component-overview/7529/pdfjs-viewer-reactive 

And many more.

Regards,

Daniel





UserImage.jpg
Fabiano Ferreira


Iconverted a form to a base64 file and now i want to open it in a tab or html format or maybe a new screen

UserImage.jpg
Stefan Weber

Maybe the javascript component you use expects an ArrayBuffer ? I once had the situation where i needed to convert a base64 to an arraybuffer. This code does it ( var aBuffer = Base64Binary.decodeArrayBuffer(<your base64 string>)


var Base64Binary = {

_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",


/* will return a  Uint8Array type */

decodeArrayBuffer: function(input) {

var bytes = (input.length/4) * 3;

var ab = new ArrayBuffer(bytes);

this.decode(input, ab);


return ab;

},


removePaddingChars: function(input){

var lkey = this._keyStr.indexOf(input.charAt(input.length - 1));

if(lkey == 64){

return input.substring(0,input.length - 1);

}

return input;

},


decode: function (input, arrayBuffer) {

//get last chars to see if are valid

input = this.removePaddingChars(input);

input = this.removePaddingChars(input);


var bytes = parseInt((input.length / 4) * 3, 10);


var uarray;

var chr1, chr2, chr3;

var enc1, enc2, enc3, enc4;

var i = 0;

var j = 0;


if (arrayBuffer)

uarray = new Uint8Array(arrayBuffer);

else

uarray = new Uint8Array(bytes);


input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");


for (i=0; i<bytes; i+=3) {

//get the 3 octects in 4 ascii chars

enc1 = this._keyStr.indexOf(input.charAt(j++));

enc2 = this._keyStr.indexOf(input.charAt(j++));

enc3 = this._keyStr.indexOf(input.charAt(j++));

enc4 = this._keyStr.indexOf(input.charAt(j++));


chr1 = (enc1 << 2) | (enc2 >> 4);

chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);

chr3 = ((enc3 & 3) << 6) | enc4;


uarray[i] = chr1;

if (enc3 != 64) uarray[i+1] = chr2;

if (enc4 != 64) uarray[i+2] = chr3;

}


return uarray;

}


}

UserImage.jpg
Fabiano Ferreira

I take the information in a form and put it in a ListAppend and the javascript is empty, I thought of maybe putting something in javascript, but I'm still not sure what

UserImage.jpg
Stefan Weber

Do you have an input parameter of type binary data in your javascript that is assigned the output of the Base64ToBinary Action ?

Still iam not really sure what you want to achieve :-(

UserImage.jpg
Fabiano Ferreira

Yes, I want to get the data that goes in the form field, I use a componte to convert it to binary and open it in a new tab in pdf format. It would be a print label.
Ícone "Verificada pela comunidade"


2026-03-16 00-00-40
Palak Patel
Solution

Dear Fabiano,
Greetings of the day

We had exactly same situation few days back and we found 2 ways to achieve that in Mobile App:
1) Using JavaScript
- > you can open binary directly in JavaScript using following command:
-------------------------------------------------------------------------------------------------------------
window.open("data:"+mimetype+";base64,"+$parameters.BinaryData, "_blank");
-------------------------------------------------------------------------------------------------------------
(here
BinaryData is input parameter with datatype as Binary Data
MimeType
we are using as application/pdf or image/jpeg. You can use as per your document type

)

2) Using FilePlugin
-> This plugin handles mostly all mimetype and you just need to input BinaryData/FileName/MimeType.
-> But you need to first save the document and then open it using your saved locaction URI or URL.


Hope I am clear to explain you the scenarios which can help to solve your development.

Thanks & Regards,
Palak Patel

UserImage.jpg
Fabiano Ferreira
achieve using the java script I found this format that met well. Thanks!


/*jshint esversion: 6 */
// --- Bibliotecas utilizadas
/*
CryptoJS v3.1.2
code.google.com/p/crypto-js
(c) 2009-2013 by Jeff Mott. All rights reserved.
code.google.com/p/crypto-js/wiki/License
*/
var pdfWindow = window.open("");
pdfWindow.document.write(
    "<iframe width='100%' height='100%' src='data:application/pdf;base64, " +
    encodeURI($parameters.input) + "'></iframe>"
);
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.