Converting binary data to text

Converting binary data to text

  

Hi everyone, I have binary data that I would like to convert into a text file and store that file in a server.  I don't want the user to download the file.  I want that to happen behind the scene.  So for example while the user clicks on a button, the file will be created, then from there it will be stored to a server without the user being aware of that.  How can I go about doing that.  
Any help would be greatly appreciated.  Thanks

Bruno Fonte wrote:

Hi,

Is this what you are looking for: https://success.outsystems.com/Documentation/10/Reference/OutSystems_APIs/BinaryData_API#BinaryDataToText?

That part is fine, but how do i convert that text into a file?


You may look into https://www.outsystems.com/forge/component/68/filesystem/ or, if you need to write to a different server, http://www.outsystems.com/forge/component/99/network-filesystem/.

I think this will get that part of the job done.

Bruno Fonte wrote:

You may look into https://www.outsystems.com/forge/component/68/filesystem/ or, if you need to write to a different server, http://www.outsystems.com/forge/component/99/network-filesystem/.

I think this will get that part of the job done.

One more question I was looking into the filesystem component.  I don't quite see anything that would allow for me to convert text to a file. Is there something that does that?

Solution

Hello Jerry,

I think you may be confused about what a binary and a text information is.

Text IS binary. It is stored in memory or any persistent media as a series of numeric values that are, in the end, just binary information.

How you interpret this data is what makes it different.

So, if you have binary data that is not a text (an English essay for example), but instead, is an image, where each byte represents a pixel, if you store it in a file and save it with a TXT, than open in a text editor, it will interpret it as text and will show you a series of characters that probably will not make sense.

So, if your binary data is NOT text, you can simple give it as the content of a file and save it using file system component. You don't need even make any kind of conversion.

If it is plain text, stored in a binary field, you can do the same thing.

You only need, and can, convert from binary to any other format, including text, if the user of the file will use it in a specific context that requires a special format.

Ex.: you have a jpeg image, but the file you want to save needs to be in base64 code. Than you can convert, because you know what the source is and you know what the result must be.

Otherwise, just save the binary to a file. No need to convert anything.

In any case, if you need to convert, you will not do it with file system. On it you will simply get the result of the conversion previously made and use as the content of your file.

Cheers

Eduardo Jauch


Solution

Jerry,

If you use "File_Write_Text" feeding it the result of "BinaryDataToText" you should get what you are looking for.

But please, take into account what Eduardo Jauch posted.

I'm trying to give the direct answer to what you are asking. Maybe if you tell us a little more about your need, something adds up to a better answer. 

Bruno Fonte wrote:

Jerry,

If you use "File_Write_Text" feeding it the result of "BinaryDataToText" you should get what you are looking for.

But please, take into account what Eduardo Jauch posted.

I'm trying to give the direct answer to what you are asking. Maybe if you tell us a little more about your need, something adds up to a better answer. 

Thanks, I took into account what Jauch said.  I ended up using the File write binary action.  The only issue that I am having is that I gave a path to store the file into my temp folder, but I can't find the file, and I am not getting any errors.  I am using a path like this.  See below.  Is there any specific format I need to use or is that format okay.

"C:\Windows\Temp\myfile.txt"



I think that the way you are giving your path is correct. Are you sure there are no permission errors? Be sure to have exception handler along side your flow.


Hi Bruno,

Keep in mind that your web app runs on the server, so any file you are attempting to write is written on the drive of the server, not on your local drive. Or do you mean you can't find it on the server? Did you check Service Center to see if there are any errors there?

Normally, IIS is not allowed to write to random directories on the server, so writing to c:\temp might very well fail. There are ways to overcome this, if you have control over the server, but on a cloud server that's a no-go.

If you explain more of your use-case, I might be able to offer some alternatives.


Kilian Hekhuis wrote:

Hi Bruno,

Keep in mind that your web app runs on the server, so any file you are attempting to write is written on the drive of the server, not on your local drive. Or do you mean you can't find it on the server? Did you check Service Center to see if there are any errors there?

Normally, IIS is not allowed to write to random directories on the server, so writing to c:\temp might very well fail. There are ways to overcome this, if you have control over the server, but on a cloud server that's a no-go.

If you explain more of your use-case, I might be able to offer some alternatives.


Thanks for the information.  I was trying to write on my local drive actually, and yes I did check Service Center and I wasn't getting any errors. The use case is actually to save the binary data into a file and save it to a server.  I was trying my local drive as a test to see if it would work.  But i am going to save it to the server and check, If I am getting some errors I will let you know.  Thanks for the help.


Hey Jerry,

Just a quick note, I'd suggest you'd save some data in the database (either the file itself as a string or blob, or the file location on the server) along with the file mime-type (if you want to return the file as a binary you'd need to know what file extension it had).


Cheers,


Joey.