Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Swiip
Contributor
Contributor

tRestClient call of api to get a picture

I use the tRestClient component to execute a GET on an API to get a picture in the answer.

I tried with Postman and i got a binary file with the extension ".bin".

If i rename this file with the extension ".jpg" i can see the picture.

But in Talend with tRestClient i can't generate the correct picture.

I tried to do this :

tRestClient => tmap => tFileOutputRaw

In the tmap i choose only the string (and not statusCode and body). In the tFileOutputRaw i generated a file. But it's not a picture. The size of this file is 24 ko. And with my test on Postman the size of the file is 25 ko. If i rename the file generated with the extension ".jpg" it isn't a picture.

Thank you very much for your help.

Have a good day

Labels (3)
45 Replies
Swiip
Contributor
Contributor
Author

You can convert this binary to a byte array then write it on a file with the java.io.FileOutputStream class.

 

How to do this ?

Thanks

Swiip
Contributor
Contributor
Author

So i put this code in a tJavaRow directly after the tRestClient ?

gjeremy1617088143

In a tjava row

 

byte[] bytes = (your input).getBytes();

      java.io.File fp = new java.io.File(the full path of the file you want to create);

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

      fos.write(bytes);

      fos.close();

 

 

path have to be like "C:/******/yourfile.JFIF"

Swiip
Contributor
Contributor
Author

I generated a file of 44 Ko but i can't open it as a picture

Swiip
Contributor
Contributor
Author

If i open the generated file with Notepad :

Swiip
Contributor
Contributor
Author

In the path in "java.io.File fp = new java.io.File( )" i tried with the extension .jpg and .jfif and .bin and i have the same result. If i rename after the extension i haven't a photo.

Swiip
Contributor
Contributor
Author

The file is 44ko and not 25ko as the file generated by Postman

gjeremy1617088143

could you send the content or it's under some entreprise or client restriction?

(the postman response) string

Swiip
Contributor
Contributor
Author

 
Swiip
Contributor
Contributor
Author

And the correct file from the answer of Postman (after renaming .bin into .jpg)