Hi guys,
In reactive web application i need to convert text to BinaryData on client side for that i have used forget component called TexttoBinaryData Client side but i am getting a window.btoa error.
please let know are there any solution to convert TexttoBinaryData on clientSide.
Hi Nani,
The plugin is cannot handle UTF-8, so what I do is adding unescape(encodeURIComponent to the original plugin function of "TextToBinaryData" from the plugin (check the screenshot)
From what I test, this should works. I also attached the modified oml.
Next time you post a question about using a Forge component, select on the form where you post a question the Forge component. This makes it easier for people to understand which component, and also the team of the component gets a notification.
I could not find the component you refer to.
Regards,
Daniel
Well, this is the Forge component link
https://www.outsystems.com/forge/component-overview/3242/binarydata-client-side
That component does work for me perfectly.
Did you look at the Demo app on how to use it?
Hi,
Please try the following Forge component, also has great demo app, and a Try Me button, so you can even see how it works before installing the component.
It does work, I can confirm that. You probably have to update the references on the demo app and publish it before trying.
Its giving me error.
I wrote my own Javascript
var encoder = new TextEncoder('utf-8');
var binaryData = encoder.encode($parameters.Text);
var encodedText = window.btoa(String.fromCharCode.apply(null, binaryData));
$parameters.BinaryData = encodedText;
its working but giving stack error.
Why you write your own JavaScript, to use the Forge component with success you need to follow the instructions as demonstrated in the Demo App. All you need to do is use BinaryAndText\TextToBinaryData
I am having api output which is text data and i have to make changes in the text and convert into binary and store it in table.
That text will have special characters and emoji and symbols that forge component will fail and length can be dynamic present i am work on text having 4072624 Characters.
example:
Text = "name":"🌈 Design ", "characters":"FAQ’s", "lastModified":"2023-12-26T10:39:44Z"
If you have time try to convert the text which i have given above, you will find out that component will raise a error.
why do you need to convert this text (which isn't just text) to binary?
Hi Nani, I hope you are well.
To transform text into binary using javascript, you can use :
const texto = "Hello, world!";
const bytes = texto.split("").map((c) => c.charCodeAt(0));
const arrayBuffer = ArrayBuffer.from(bytes);
const fileSaver = new FileSaver();
fileSaver.save(new Blob([arrayBuffer]));
$resolve();
You will need to replace the input and output parameters in the code.
Hi nani,
you can also try this one hope this should help you.
Thanks,
Narendra Tiwari
Hi @Narendra Tiwari
The author is asking about converting binary data on client side, what your suggest is on server side.
Hope this helps as an additional information.
I have tried my best for client side conversation, JavaScript raising error like scripts missing, librarys needed, stack Overflow, Window.btoa, etc...,
I know the extension works pretty good but it is a server side.
Well now i am using the extension but i have increased the server time out.
thank you for your all support.
In future if you find a solution please let know.
Can you give the oml ? I also use binarydata-client-side and it always works fine.
Let me check from your oml.
Its not just a text there are also some symbols, special character, emoji's, etc..,
I have a created test screen for that.
Thanks. It Works. Even in ODC.
Hi Nani, I just take a look at your code. btoa doesn't really handle UTF8-strings - it's ASCII only. You had fixed that by writing your own code.About Maximum call stack size exceeded error : As you researched, it usually occurs when there is excessive recursion, leading to the call stack growing beyond its limit. In your code, it happens at String.fromCharCode.apply(null, binaryData). On large data like 4072624 Characters, using apply lead to that error.I suggest to break the data into smaller chunk
function test(Text) {
var binaryData = encoder.encode(Text);
var CHUNK_SIZE = 0x8000; // 32k define your chunk size
var chunks = [];
for (var i = 0; i < binaryData.length; i += CHUNK_SIZE) {
chunks.push(binaryData.slice(i, i + CHUNK_SIZE));
}
var encodedText = '';
chunks.forEach(function(chunk) {
encodedText += window.btoa(String.fromCharCode.apply(null, chunk));
});
return encodedText;