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

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Dobby1
Contributor III
Contributor III

Convert jpg file to base64

I'm using tFileInputRaw to read a jpg file followed by tJavaRow to get the base64 encoding for the file. I get "java.lang.NullPointerException: Cannot read the array length because "src" is null" at the line in the tJavaRow when I attempt to encode the byte array. I've set the Mode for the tFileInputRaw to Read the file as a bytes array. I also tried the other modes without success. Here's the code in the tJavaRow:

 

byte[] bytes = (byte[]) output_row.content;

//Encode the byte array to a Base64 string

String base64String = java.util.Base64.getEncoder().encodeToString(bytes);

//Pass the Base64 string to the output column

//output_row.base64ImageString = base64String;

Labels (3)
1 Solution

Accepted Solutions
Shicong_Hong
Employee
Employee

Hello 

To access the input data, here should be input_row.content rather than output_row.content.

byte[] bytes = (byte[]) input_row.content;

//Encode the byte array to a Base64 string

String base64String = java.util.Base64.getEncoder().encodeToString(bytes);

 

Regards

Shicong

View solution in original post

3 Replies
Shicong_Hong
Employee
Employee

Hello 

To access the input data, here should be input_row.content rather than output_row.content.

byte[] bytes = (byte[]) input_row.content;

//Encode the byte array to a Base64 string

String base64String = java.util.Base64.getEncoder().encodeToString(bytes);

 

Regards

Shicong

Dobby1
Contributor III
Contributor III
Author

Hello,

Thank you. I switched to input_row and got the same error at the same line. I then changed the name of the flow between the tFileInputRaw to the tJavaRow2 from "output_row" to row4 and the error disappeared.

Are "input_row" and "output_row" special attributes/properties for a tJavaRow?

Shicong_Hong
Employee
Employee

Hi @Dobby1  if you need to access the input data, should use "input_row.columnName". To assign the data to next component, use "output_columnName".