Hi,
We're using this component but ran into an issue when trying to use TextToBinaryData with text that contains non-Latin1 characters, such as ‘. The fix to this is the following (changes in bold):
In TextToBinaryData, do:
var encodedText = window.btoa(unescape(encodeURIComponent( $parameters.Text )));$parameters.BinaryData = encodedText;
In BinaryDataToText, do:var toBase64 = $parameters.Binary;$parameters.Text = decodeURIComponent(escape(window.atob(toBase64)));Would be great if this fix could be included in the component.
Kind regards,
Steven
Hi @Steven Decock
Can you please share an example of an image to test that scenario? Just tested your code with a random image and got runtime errors.
Cheers,GM
Hi Gonçalo,
I'm not using TextToBinary and BinaryToText for images. I'm using it so I can download a JSON export (so actual text in a Local Variable) to a Binary, to download. And then on import I do BinaryToText to convert it back to the JSON. But if the JSON contains non-Latin1 characters, that fails. That's why I made my changes with unescape and encodeURIComponent.
Indeed, my code would not work for images. But why would one want to use BinaryToText or TextToBinary for images? I'm trying to think of usecases. For images it seems to make more sense to just Base64 the image using BinaryToBase64.
In any case, my code does indeed presume that the binary content that you pass to BinaryToText is a binary representation of something that is text.
But, like I said, if you want a text-representation of a Binary that is not pure text, then why not use BinaryToBase64?
I too had this exact same issue then converting a JSON to a Binary with this action. The JSON was created via the native JSONSerialize action. The only thing is that is needed to trigger this error is that at least one property needed to contain some of these chars (have not tried to figure out which is not accepted. I think it's the "`" though.
Test chars: %^~|[] <>{} @#&*-+=()_€"':;/
When changing to the solution Steven provided the issue was solved. Would love to see this fixed in the base component.
As for why I'm saving a JSON to binary. It is a complicated JSON structure and creating a database structure for this is unneeded bloat (and therefor license costs). The data the structure contains is filled during a wizard and uploaded when there is an internet connection. When online we are then able to send the data as quick as possible to the backend before the connection is broken again.