Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
Hi, I think you can use tfileFetch component instead of tRestClient component. It will write directly the response into a file.
Hi, TRestClient send you a Json response, you have to parse it via a parser component like TExtractJsonField.
Send me Love and Kudos
But when i launch the same api with Postman and i click on "Save Response" i have directly the binary file and not a Json answer.
could you send a screenshot of the body response in postman ?
In attachment.
Thanks
It's seem to be a binary of a JFIF
Yes in fact it's a photo. When i click on "Save Response" i have a response.bin
If i rename the extension in response.jpg i can see the photo.
You can convert this binary to a byte array then write it on a file with the java.io.FileOutputStream class.
public static String 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();
return null;
} catch (IOException e) {
return e.toString();
}
}