One Star

[resolved] Invoking a Rest Service for file upload

Hi,
I need to invoke a rest service that do a file upload.
I used tRest component, configured it and used a contex variable to pass file data to http body parameter. But I don't know how set data file into context variable and then how pass this data in input to tRest component.
Anyone can help me pleae?
thanks in advance.
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] Invoking a Rest Service for file upload

Hi,
Tibco BW is a little bit different, nevertheless an ESB too Smiley Happy (I am an iPE expert)
ok.. this works as designed. tFileRow reads the input file ROW by ROW and sends a ROW of data to process.
in the tMap component you have to define an output structure and map input to the tMap output. Then the iterator should have a property with name of the tMap output, something like ((String)globalMap.get("row3_output")). (NB_LINE is the number of lines)
As far I know there is no direct component that reads all the file content at once, you can read CSV, excel, xml, ldif, json, . that's why ir would be great if it would be a structured file (e.g. tFileReadXML would post the whole XML or it's part). Maybe tFileInputRegex would do it
let's play a little
have fun
gabriel
3 REPLIES
One Star

Re: [resolved] Invoking a Rest Service for file upload

Hi,
it's not necessary to use a context variable (use it for configuration purposes). You will have to load the file content into a row container, e.g. reading an XML file, the job will look such as
tFileXmlInput -> tWriteXMLField (or tXMLMap) -> tFlowToIterate -> tRest
than rename the tFlowToIterate component to e.g. "iterator" and in the tRest body you will able to use iterator.xmlField (Ctrl-Spacewill propagate you available options and then it will convert the input into a executable expression)
It will work for structured files, e.g. XML, CSV, etc, but to load an unstructured content - I guess you will have to do a function for it (e.g. create a bean)
Carpe diem
Gabriel
One Star

Re: [resolved] Invoking a Rest Service for file upload

Thank you very much Gabriel, I've tried something like that but I've missed the tFlowIterate and cannot link the tRest.
Now, I've tried with tFilewInputRow-->tMap-->tFlowToIterate-->tRest
In tRest Body I have something like this: <fileContent>" + ((Integer)globalMap.get("tFlowToIterate_1_NB_LINE")) + "</fileContent>
But service has called n times (one for row).
Sorry I'm quite new to Talend, but had experience with Tibco BW that looks like.
One Star

Re: [resolved] Invoking a Rest Service for file upload

Hi,
Tibco BW is a little bit different, nevertheless an ESB too Smiley Happy (I am an iPE expert)
ok.. this works as designed. tFileRow reads the input file ROW by ROW and sends a ROW of data to process.
in the tMap component you have to define an output structure and map input to the tMap output. Then the iterator should have a property with name of the tMap output, something like ((String)globalMap.get("row3_output")). (NB_LINE is the number of lines)
As far I know there is no direct component that reads all the file content at once, you can read CSV, excel, xml, ldif, json, . that's why ir would be great if it would be a structured file (e.g. tFileReadXML would post the whole XML or it's part). Maybe tFileInputRegex would do it
let's play a little
have fun
gabriel