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

Sorry i don't know if i am clear.

The first file = file generated by Talend

The second file = file generated by Postman

gjeremy1617088143

I suspect an encoding problem .

you can do two things. Check the header generated by postman for encoding and set them on the tRestClient And after force the Jvm default charset for encoding

Swiip
Contributor
Contributor
Author

If i run the api with Postman i can see in Headers :

Accept-Encoding = gzip, deflate, br

Content-Encoding = gzip

 

So i added Content-Encoding = gzip in the parameter of the tRestClient but i have an error 400 :

 

0695b00000EahFHAAZ.png0695b00000Eah66AAB.png 

gjeremy1617088143

You have to put them in advanced settings view of the component , HTTP headers. and put this :

key : "Content-Type"

value : "text/html; charset=iso-8859-1"

it will force the encoding of the response.

 

 

Swiip
Contributor
Contributor
Author

The result is the same a file of 44ko0695b00000EahgmAAB.png

Swiip
Contributor
Contributor
Author

In Postman i saw Content-Type=application/octet-stream

So i tried this in the HTTP header of tRestClient but same result a file of 44ko

 

0695b00000EahrBAAR.png

gjeremy1617088143

maybe "application/octet-stream; charset=binary"

 or "application/octet-stream; charset=iso-8859-1"

and you can put -Dfile.encoding=ISO-8859-1 in your jvm parameter

 

cause you have difference in file size explain by bad encoding, by the parameters give in the response or by Talend (by default Talend use UTF-8 in te JVM.

 

Swiip
Contributor
Contributor
Author

Same result a file of 44ko :

0695b00000EaiDqAAJ.png

Swiip
Contributor
Contributor
Author

I tried "application/octet-stream; charset=binary" => file of 44 ko not correct

I tried "application/octet-stream; charset=iso-8859-1" => file of 44 ko not correct

I tried -Dfile.encoding=ISO-8859-1 in your jvm parameter => file of 24 ko not correct

The correct size is 25 ko.

 

0695b00000EaiGGAAZ.png

Swiip
Contributor
Contributor
Author

I renamed the extension of the postman response in .txt and i renamed also the extension of the file generated by talend in .txt.

After this i compared the 2 files with the tool Winmerge.

Below at the left the file of 44 ko generated by Talend and at the right the file generated by Postman.

At the bottom of the screen of Winmerge we can can see UTF-8 at the left and Windows 12-52 at the right

 

 

0695b00000EaiH4AAJ.png