Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Ashok200792
Contributor
Contributor

How to Convert image to base64 format ?

How to convert the images into the base64 encode and decode 

 

We use the tJavaRow for encode base64 --->>

 

//Start

 

File file = new File("/home/user/logo.png");
byte[] bytes = loadFile(file);
String s = new sun.misc.BASE64Encoder().encode(bytes); 

System.out.println(s);

 

//end

 

error Message:

Detail Message: File cannot be resolved to a type

 

Can you guide me further process

Labels (1)
2 Replies
Anonymous
Not applicable

Go to your tJavaRow's Advanced Settings and add this line of code....

 

import java.io.File;
Ashok200792
Contributor
Contributor
Author

Program : tJavaRow

code:

 

File file = new File("/home/user/logo.png");
FileInputStream imageInFile = new FileInputStream(file);
byte imageData[] = new byte[(int)file.length()];
imageInFile.read(imageData);
//String imageDataString = encodeImage(imageData);
String imageStr = new sun.misc.BASE64Encoder().encode(imageData);
System.out.println("OKAy:"+imageStr);
imageInFile.close();

No error shown but we cannot get return any string value "System.out.println("OKAy:"+imageStr);"