Read file content & encode to base64

Hi,
How can i read a JSON file & encode its content to base64. I don’t want to parse the file data. Just read it & encode. I am trying to pass an encoded file contact to external system.

Thanks,

Hello,

If you do not care about the content of the file and just want to convert the whole input file into it’s base64 form, it is quite easy. Read the file as a stream of bytes and convert it using byte2base64 function of CTL. PFA example graph.
json_to_base64.zip
Regards,

Thanks for your reply. I implemented very similar approach as yours. I think the trick to this is how you define metadata.

I used this topic “Reading a CR/LF filled XML file into one metadata record” to find the solution.

Couple of question:

1. At runtime, does the UniversalReader determine the output type of the file content to be byte or String based on the metadata or is there a setting for that. The way i implemented it first read it as String & then use byte2base64(str2byte($in.0.json_object,“utf-8”)). In ur sample the output from UniversalData reader is byte.

2. I have a requirement to read 10 GB csv file, then encode base64 & split it out as chunks of 1GB to target. I don’t think I can read the whole file & bring it to memory before encoding. What kind of option do we have? Looks like ParalleReader might be an option but am not sure how to batch them in series of 1gb. Any idea?

1. I do not know how exactly do you want to work with the output metadata, but unfortunately, UniversalDataReader can not determine output metadata at runtime by itself.

2. You can use UniversalDataReader for reading 10 GB file. When you read a big file via UniversalDataReader, the whole file is not read into the memory but the reading works in stream mode.