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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
diggi86
Contributor
Contributor

Reading a byte array from a json file and then convert it into xlsx file

I have a small use case wherein I need to fetch an excel file from an api response. The api response is of json format and I need to

1.) read the json element which contains byte array (byte[])

2.) convert the byte array to a excel file.

0695b00000HB7wgAAD.png 

I have set the data type as byte[] for my JSON coloumn containing the byte array.

The output.file_contents contains the byte array which I am sending to java routine to convert it into a xlsx file.

The code for my tjava is quite a simple one.

 

System.out.println(input_row.file_contents);

Write.ByteArrayToFile(input_row.file_contents, context.finalPath) ;

 

The for my routine is

package routines;

public class Write {

  public static void ByteArrayToFile(byte[] input, String filepath) {

  try 

  { 

  java.io.File fp = new java.io.File(filepath);

  java.io.FileOutputStream fos = new java.io.FileOutputStream(fp);

  fos.write(input);

  fos.close();

  }

  catch(Exception err)

  {

  err.printStackTrace();

   

  }

  }

  }

  

The talend code is executing and also creating an xlsx file at desired location. However, everytime when I open my excel it gives an error as

0695b00000HB7zBAAT.png 

Any help in this will be really apprciated. I think the isse is how I am reading the json file. However when I am trying to print the byte array I can properly see it values as

0695b00000HB81bAAD.png

Labels (2)
1 Reply
Anonymous
Not applicable

To test your routine code, you can use tFileInputRaw to read the whole file as a bytes array.

 

Regards

Shong