Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
Simple proxy solution:
Problem. It seems to me that tHTTPClient by default casts the body response part into String and corrupts file binrary by doing it.
When I fetch the document using tHTTPClient_1, there are options
How can I map the "cached" file into tHTTPClient_2 request body?.
Have not found any good reference where "use cache to save file" stores the content internally in Talend and how to refer to it later on.
NB! I'm not interested to use the option to store the file into local disk folder in the middle of the flow.
I would prefer that file binary to be carried over by Flow from tHTTPClient_1.response -> tHTTPClient_2.request.
Regards,
Rait
Hello Rait.
Use cache to save file will store the file into a Stream that can be accessed with global variable.
For example if your tHTTPClient is named tHTTPClient_1 :
You will have a global variable named tHTTPClient_1_HTTP_INPUT_STREAM
From the Input Stream you can do what you want.
Here I wrote a .pdf file in c:/pdf folder from the tHTTPClient response attachment :
java.io.InputStream inputStream = ((java.io.InputStream)globalMap.get("tHTTPClient_1_HTTP_INPUT_STREAM"));
java.io.FileOutputStream outputStream = new java.io.FileOutputStream("C:/pdf/test1.pdf");
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
inputStream.close();
Best regards
Jérémy
Hello Rait.
Use cache to save file will store the file into a Stream that can be accessed with global variable.
For example if your tHTTPClient is named tHTTPClient_1 :
You will have a global variable named tHTTPClient_1_HTTP_INPUT_STREAM
From the Input Stream you can do what you want.
Here I wrote a .pdf file in c:/pdf folder from the tHTTPClient response attachment :
java.io.InputStream inputStream = ((java.io.InputStream)globalMap.get("tHTTPClient_1_HTTP_INPUT_STREAM"));
java.io.FileOutputStream outputStream = new java.io.FileOutputStream("C:/pdf/test1.pdf");
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
inputStream.close();
Best regards
Jérémy
Hi @Gjeremy
Thank you very much for the _INPUT_STREAM hint.
tHTTPClient_1_HTTP_INPUT_STREAM was the missing piece in the puzzle for me.
( https://help.qlik.com/talend/en-US/components/8.0/http/thttpclient page needs update in Global Variables section in regards of this )
While we are at cHTTPClient.
Any hint how to map binary from tHTTPClient_1_HTTP_INPUT_STREAM to tHTTPClient_2 PUT request body?
By default when request body type = binary, the option is enabled to read from file. No clear understanding how to map binary from global variable instead.
Regards,
Rait
Hi @Rait,
On tHTTPClient component when the body type is set to Binary,
you can only refer to the path of an existing file.
In the code I can see it will create a FileInputStream based on the file path :
} else if (bodyType == BodyFormat.BINARY) {
InputStream fileInputStream = new FileInputStream(this.queryConfiguration.getFilePath());
Do you have an example of a call for the webservice were you need to send the binary ?
Best regards
Jérémy
Hi @Gjeremy
As I mentioned in original post.
1. Downoload binary from one webservice ( store it in cache: tHTTPClient_1_HTTP_INPUT_STREAM)
2. Upload binary to other webservice ( binrary from globalVariable/cache)
It's common integration pattern.
Or one can have scenario where:
1. you receive binary as Base64 decoded string. ( Doesn't matter much how you get it 🙂 )
2. you decode Binary ( store it into GlobalVariable)
3. you need to send Binary to Webservice that expects binary to be in request body.
Staring point in all cases would be, that you have binary in GlobalVariable and not in local harddrive as file.
with old tREST component it was simple. There is nice-clean-easy option to map into request body from (byte[])globalMap.get("YourBinaryVariable"). Works like charm.
But that component is deprecated and I would rather use tHTTPClient or tRESTClient components instead.
I'm not interested to create temporary file on local drive - extremely dumb way to implement such integration.
If data is already in memory/cache/globalVariable etc. I want to use it directly from there.
I know there is possibility is to write custom Java HTTP client into tJavaRow etc. but that is ugly workaround in my eyes. I would prefer to use out of box components tHTTPClient or tRestClient etc.
Regards,
Rait