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
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
So i put this code in a tJavaRow directly after the tRestClient ?
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"
I generated a file of 44 Ko but i can't open it as a picture
If i open the generated file with Notepad :
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.
The file is 44ko and not 25ko as the file generated by Postman
could you send the content or it's under some entreprise or client restriction?
(the postman response) string
And the correct file from the answer of Postman (after renaming .bin into .jpg)