Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Alpha549
Creator II
Creator II

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 ?

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable

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 😉

View solution in original post

5 Replies
Anonymous
Not applicable

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.

 

0695b00000N3MXKAA3.pngAbove is the "Basic settings" tab. Here you set the URL of the REST service.

 

0695b00000N3MYhAAN.pngThe 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.

Alpha549
Creator II
Creator II
Author

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.

Anonymous
Not applicable

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 😉

Alpha549
Creator II
Creator II
Author

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 !

Anonymous
Not applicable

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 😉