
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
tRestClient : send a file with FORM content type and POST
Hello everyone,
I have to send a file using a tRestClient.
I set HTTP Method to POST, Content-Type to FORM, and Accept Type to JSON.
I imagine that I must read the file data using tFileInputRaw, and then pass this String to tRestClient component as "string" field ?
Has anyone already send files using a REST API ?
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can get the response by filling in the "Destination directory" and "Destination filename" fields. This will create a file which you can read in a subjob that runs after this process (by subjob, I mean a series of components that are linked to the tFileFetch via a OnSubJobOK link.
Unfortunately sending files via the tRestClient like this isn't supported. However, one of the significant advantages of Talend Studio is that you can anything like you with Java. So, if you are able to write Java you can write this for yourself with a routine and a tJavaFlex. I'd knock something up now if it weren't for the time. I'm UK based and it is getting a little late. If you are still struggling tomorrow, I'll have a go at putting something together 😉

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try using the tFileFetch component. It is better suited to this requirement. The name is somewhat misleading as it will send files as well.
Here is a quick example config that I have used for a REST service which was configured to receive form data.
Above is the "Basic settings" tab. Here you set the URL of the REST service.
The screen above shows where you set the "upload" settings. First of all tick the "Upload file" tickbox. Then you need to add a row to the "Files" table. Here you will set the "Name" which is the form name of the param which holds the filename. In my HTML file it was called "file". The "File" field is used to hold the location of the file. This can be set using a context variable, globalMap or it can be hardcoded as I have done above. You then need to set the "Content-Type" of the file and the "Charset".
Once that is all set, it will send the file to your form fed REST API.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello rhall,
I didn't know this method.
Here I have to get a code from the response, in order to run another process. With tFileFetch method I'm not sur I can get this code as a response ?
When I test the URL using Postman, the body type is form-data.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can get the response by filling in the "Destination directory" and "Destination filename" fields. This will create a file which you can read in a subjob that runs after this process (by subjob, I mean a series of components that are linked to the tFileFetch via a OnSubJobOK link.
Unfortunately sending files via the tRestClient like this isn't supported. However, one of the significant advantages of Talend Studio is that you can anything like you with Java. So, if you are able to write Java you can write this for yourself with a routine and a tJavaFlex. I'd knock something up now if it weren't for the time. I'm UK based and it is getting a little late. If you are still struggling tomorrow, I'll have a go at putting something together 😉

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @Richard Hall
I succeed in doing what I wanted !
I created a custom JAR on Eclipse and imported it in Talend !
Thank you for you help and enriching my vision !

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not a problem. Glad it worked! One last thing I feel I should offer, try not to jump straight to coding a solution in Java first. It is incredibly useful and opens many doors, but don't get caught in the trap of "reinventing the wheel". Always have a look for non-coding solutions first 😉
