[resolved] Send file to WebService

[resolved] Send file to WebService

Hi all,
I'm trying to send a file to a Webservice, along with other parameters. For reading the file I use tFileDelimited with no separators, then pass the content to tWebServiceInput. I cannot figure out how to refer that content in the parameter list from tWebServiceInput for sending it to the WebServer.
Regards,
Radu

Accepted Solutions
Community Manager

Re: [resolved] Send file to WebService

Hi
Store the content into a global variable and get it on the parameter list of tWebserviceInput, for example:
tFileInputDelimited--main--tJavaRow
|
onsubjobok
|
tWebserviceInput--main--tLogRow
on tJavaRow:
globalMap.put("file_content", input_row.content) //content is the column name on tFileInputDelimited
on tWebserviceInput, set the value of parameters as below:
(String)globalMap.get("file_content")
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

All Replies
Community Manager

Re: [resolved] Send file to WebService

Hi
Store the content into a global variable and get it on the parameter list of tWebserviceInput, for example:
tFileInputDelimited--main--tJavaRow
|
onsubjobok
|
tWebserviceInput--main--tLogRow
on tJavaRow:
globalMap.put("file_content", input_row.content) //content is the column name on tFileInputDelimited
on tWebserviceInput, set the value of parameters as below:
(String)globalMap.get("file_content")
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

Re: [resolved] Send file to WebService

Hi Shong,
It worked. Thanks for your help!
Best Regards,
Radu
Community Manager

Re: [resolved] Send file to WebService

Hi Shong,
It worked. Thanks for your help!
Best Regards,
Radu

Good news, thanks for your feedback!
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

Re: [resolved] Send file to WebService

Hi,
The file gets to the WebService in a wrong format. I guess it's not byte[] when send from WebServiceInput. I specified byte[] in FileInputDelimited's schema, and also changed the parameter expression in WebServiceInput to (byte[])globalMap.get("file_content"), but still, the received file is corrupted (is csv, xlsx,..).
Regards,
Radu
One Star

Re: [resolved] Send file to WebService

Should you not just specify it as a string?

Re: [resolved] Send file to WebService

Should you not just specify it as a string?

I did that at first, but with similar results.
Inside the talend job it seems to be ok, it has the right length, but then the webservice receives it truncated at 6 characters.
One Star

Re: [resolved] Send file to WebService

Ah! I think you need base64 encoding. I had this problem sending binary data from a webservice. Had to encode it to send from webservice and decode on receipt.

Re: [resolved] Send file to WebService

Ah! I think you need base64 encoding. I had this problem sending binary data from a webservice. Had to encode it to send from webservice and decode on receipt.

How can I encode it? Is it a componet which I have to use or encode in java?
I should mention that I'm not a java programmer.
Regards,
Radu
One Star

Re: [resolved] Send file to WebService

Use a tJavaRow for the encode/decode.
To enccode
String s = new sun.misc.BASE64Encoder().encode(input_row.Image);
//System.out.println("Text Decryted : " + s);
output_row.Image = s;
To deccode
byte[] buf = new sun.misc.BASE64Decoder().decodeBuffer(input_row.Image);
//System.out.println("Text Decryted : " + s);
output_row.Image = buf;

Re: [resolved] Send file to WebService

Use a tJavaRow for the encode/decode.
To enccode
String s = new sun.misc.BASE64Encoder().encode(input_row.Image);
//System.out.println("Text Decryted : " + s);
output_row.Image = s;
To deccode
byte[] buf = new sun.misc.BASE64Decoder().decodeBuffer(input_row.Image);
//System.out.println("Text Decryted : " + s);
output_row.Image = buf;

Thanks Jan! Now it works.
Best Regards!
One Star

Re: [resolved] Send file to WebService

Would be the same procedure to send an XML to a Restful Web Service or is there something better?
One Star

Re: [resolved] Send file to WebService

I think it only applies to binary data. Text should be ok.
One Star

Re: [resolved] Send file to WebService

Hello, I was wondering if this process for encoding goes after you send the content of the file through a String.
tFileInputDelimited--main--tJavaRow--Encoding--output

Thank you!