Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Convert String to base64

Hi. Im kind of newbie in all these things and definitely cannot code, so please be patient with me 0683p000009MACn.png In our Salesforce org we have custom Note field (String) on Account object. There is a new Notes feature (introduced few releases back), information is stored in ContentNote object, in the Content field, which is base64 type. Im trying to migrate old Notes in new Notes. Im facing the problem to convert the data from String to base64. I found the article where was recommended to use tJava component with following code:

String s = new sun.misc.BASE64Encoder().encode(out.Content);
            //System.out.println("Text Decryted : " + s);
            row4.Content = s;

I tried this but unfortunately it doesnt work, I received an error saying: 

Error in the component's properties:The method encode(byte[]) in the type CharacterEncoder is not applicable for the arguments (String)

Can anyone please help? See attached pictures. For this moment Im just trying to create records in new Notes, I will relate them to Accounts in next step. Many thanks for help0683p000009Lv6m.png0683p000009Lv4C.png0683p000009Luy0.png

 

Labels (1)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

I think you need to convert String to bytes array before to encode.

Here is a example from StackExchange for the conversion:

String example = "Convert Java String";
byte[] bytes = example.getBytes();

You need to put this in the tJava (or tJavaRow) and pass the result to BASE64Encoder.

Something like that:

byte[] b = out.Content.getBytes();
String s = new sun.misc.BASE64Encoder().encode(b);
row4.Content = s;

If it doesn't solve your problem, let us know.

View solution in original post

3 Replies
TRF
Champion II
Champion II

I think you need to convert String to bytes array before to encode.

Here is a example from StackExchange for the conversion:

String example = "Convert Java String";
byte[] bytes = example.getBytes();

You need to put this in the tJava (or tJavaRow) and pass the result to BASE64Encoder.

Something like that:

byte[] b = out.Content.getBytes();
String s = new sun.misc.BASE64Encoder().encode(b);
row4.Content = s;

If it doesn't solve your problem, let us know.

Anonymous
Not applicable
Author

As per above. Use the String getBytes() function. Also, use tJavaRow instead of tJava since you are in a flow.
JSey
Creator
Creator

Tried this today, but it doesn't seem to work. The source are files in sql strored as binary, and after migrating to SF the files are corrupt and cannot be open. In the SQL metadata, I have setup the column where the data is as a string.

 

Subjob:

0695b00000F7WG0AAN.png 

Here is my tJavarow Basic:

output_row.Owner_Id = input_row.Owner_Id;

output_row.Client_Id = input_row.Client_Id;

output_row.Contact_Number = input_row.Contact_Number;

output_row.Record_Id = input_row.Record_Id;

output_row.Description = input_row.Description;

output_row.Ole_Doc_Type = input_row.Ole_Doc_Type;

byte[] b = row3.TextCol.getBytes();

String s = new sun.misc.BASE64Encoder().encode(b); 

row4.TextCol = s;

 

tJavaRow Advance:

import org.apache.commons.codec.binary.Base64;

 

tmap:

0695b00000F7WILAA3.pngHelp would be appreciated, thank you.