Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
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
gjeremy1617088143
Creator III
Creator III

so :

"application/octet-stream; charset=WINDOWS-1252"

and -Dfile.encoding=windows-1252 in JVM ?

 

Swiip
Contributor
Contributor
Author

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

I tried -Dfile.encoding=windows-1252 in JVM => file of 24 ko not correct

Swiip
Contributor
Contributor
Author

If i tried "application/octet-stream; charset=WINDOWS-1252" i have this log below so we can see that we haven't the same encoding in the response:

 

Starting job API_NYTIMES at 11:55 28/04/2021.

[statistics] connecting to socket on port 3454

[statistics] connected

avr. 28, 2021 11:55:09 AM org.apache.cxf.interceptor.LoggingOutInterceptor

INFOS: Outbound Message

---------------------------

ID: 1

Address: https://fa-eoic-test-saasfaprod1.fa.ocs.oraclecloud.com:443/hcmRestApi/resources/11.13.18.05/publicWorkers/100000001631073/child/photos/300000048923477/enclosure/Photo

Http-Method: GET

Content-Type: application/octet-stream; charset=WINDOWS-1252

Headers: {Accept=[*/*], Content-Type=[application/octet-stream; charset=WINDOWS-1252], Authorization=[Basic Y2hyaXN0b3BoZS5tYWlsbGV0QGFjY2VudHVyZS5jb206QWNjZW50cnVlMDE=]}

--------------------------------------

avr. 28, 2021 11:55:09 AM org.apache.cxf.interceptor.LoggingInInterceptor

INFOS: Inbound Message

----------------------------

ID: 1

Response-Code: 200

Encoding: ISO-8859-1

Content-Type: application/octet-stream

Headers: {Cache-Control=[no-cache, no-store, must-revalidate], connection=[keep-alive], Content-Language=[en], Content-Length=[24659], content-type=[application/octet-stream], Date=[Wed, 28 Apr 2021 09:55:10 GMT], ETag=["ACED0005737200136A6176612E7574696C2E41727261794C6973747881D21D99C7619D03000149000473697A65787000000001770400000001737200116A6176612E6C616E672E496E746567657212E2A0A4F781873802000149000576616C7565787200106A6176612E6C616E672E4E756D62657286AC951D0B94E08B02000078700000000278"], Link=[<https://fa-eoic-test-saasfaprod1.fa.ocs.oraclecloud.com:443/hcmRestApi/resources/11.13.18.05/publicWorkers/100000001631073/child/photos/300000048923477/enclosure/Photo>;rel="self";kind="other";name="self"], Location=[], REST-Framework-Version=[1], Strict-Transport-Security=[max-age=31536000; includeSubDomains], X-Content-Type-Options=[nosniff], X-ORACLE-DMS-ECID=[005kGLVoGcMDg^Xptsk3yX0001Ae00017K], X-XSS-Protection=[1; mode=block]}

Messages: --- Binary Content ---

 

--------------------------------------

[statistics] disconnected

 

Job API_NYTIMES ended at 11:55 28/04/2021. [exit code = 0]

Swiip
Contributor
Contributor
Author

We can see this :

ID: 1

Response-Code: 200

Encoding: ISO-8859-1

Content-Type: application/octet-stream

Swiip
Contributor
Contributor
Author

But in Postman i can see Content-Encoding=gzip

Swiip
Contributor
Contributor
Author

and Content-Type = application/octet-stream

gjeremy1617088143
Creator III
Creator III

you can use Content-Type: application/octet-stream

and Content-Transfer-Encoding : base64.

then check the result in the string of the response and compare it to your document content in that you have to encode in base64.

If it's ok you have get the good encoded content of the document in base64.

so after you just have to decodebase64 and write it on a file as i mentionned before.

 

Swiip
Contributor
Contributor
Author

I tried in http header in tRestClient Content-Type: application/octet-stream

and Content-Transfer-Encoding : base64

 

I generated again a file of 44ko.

 

Below the log. We can see again :

"Response-Code: 200

Encoding: ISO-8859-1

Content-Type: application/octet-stream"

 

The full log below :

 

 

 

Starting job API_NYTIMES at 17:06 28/04/2021.

[statistics] connecting to socket on port 3646

[statistics] connected

avr. 28, 2021 5:06:17 PM org.apache.cxf.interceptor.LoggingOutInterceptor

INFOS: Outbound Message

---------------------------

ID: 1

Address: https://fa-eoic-test-saasfaprod1.fa.ocs.oraclecloud.com:443/hcmRestApi/resources/11.13.18.05/publicWorkers/100000001631073/child/photos/300000048923477/enclosure/Photo

Http-Method: GET

Content-Type: application/octet-stream

Headers: {Accept=[*/*], Content-Type=[application/octet-stream], Content-Transfer-Encoding=[base64], Authorization=[Basic Y2hyaXN0b3BoZS5tYWlsbGV0QGFjY2VudHVyZS5jb206QWNjZW50cnVlMDE=]}

Messages: --- Binary Content ---

 

--------------------------------------

avr. 28, 2021 5:06:18 PM org.apache.cxf.interceptor.LoggingInInterceptor

INFOS: Inbound Message

----------------------------

ID: 1

Response-Code: 200

Encoding: ISO-8859-1

Content-Type: application/octet-stream

Headers: {Cache-Control=[no-cache, no-store, must-revalidate], connection=[keep-alive], Content-Language=[en], Content-Length=[24659], content-type=[application/octet-stream], Date=[Wed, 28 Apr 2021 15:06:18 GMT], ETag=["ACED0005737200136A6176612E7574696C2E41727261794C6973747881D21D99C7619D03000149000473697A65787000000001770400000001737200116A6176612E6C616E672E496E746567657212E2A0A4F781873802000149000576616C7565787200106A6176612E6C616E672E4E756D62657286AC951D0B94E08B02000078700000000278"], Link=[<https://fa-eoic-test-saasfaprod1.fa.ocs.oraclecloud.com:443/hcmRestApi/resources/11.13.18.05/publicWorkers/100000001631073/child/photos/300000048923477/enclosure/Photo>;rel="self";kind="other";name="self"], Location=[], REST-Framework-Version=[1], Strict-Transport-Security=[max-age=31536000; includeSubDomains], X-Content-Type-Options=[nosniff], X-ORACLE-DMS-ECID=[005kGasY62wDg^Xptsk3yX0001Ae0000ji], X-XSS-Protection=[1; mode=block]}

Messages: --- Binary Content ---

 

--------------------------------------

[statistics] disconnected

 

Job API_NYTIMES ended at 17:06 28/04/2021. [exit code = 0]

gjeremy1617088143
Creator III
Creator III

It's really hard to debug tRestclient remotely, but you have an encoding issue for sure

Swiip
Contributor
Contributor
Author

Yes but it's strange because when i change the http header of tRestclient with Content-Type parameter i have always in the log for the response :

Encoding: ISO-8859-1

Content-Type: application/octet-stream

 

as if I don't change anything