Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
RGrahams1634
Contributor
Contributor

Modifying a composant to use parameters from a file.

Good morning everyone.

I need to implement a job that will upload files to an API. In order to do so I'm using the composant tFileFetch (I couldn't find how to send a file using the tRestClient composant).

I have succeeded in doing so with parameters specified in the "Common Parameters" area, however, i'd like to upload multiple files and the number, name and value of the different parameters will change for each file.

I was wondering if there was any way to fetch data in a file and use it to set my parameters. I'm open to any idea since i've been stuck for quite a long time now.

Thanks in advance!

Labels (2)
5 Replies
Anonymous
Not applicable

You can use a tContextLoad component to load data from a file/db/any other source into your context variables. This is demonstrated here....

https://help.talend.com/r/en-US/8.0/context/reading-data-from-different-mysql-databases-using-dynamically-loaded-connection-parameters

 

This requires the data in the file to be in a particular format which is shown in the documentation above. If the data is in a file that cannot be in that format, you can read the file in and use various Talend components to extract that data, then move it to context variables or the globalMap (see tSetGlobal Var https://help.talend.com/r/en-US/8.0/global-variable/tsetglobalvar).

RGrahams1634
Contributor
Contributor
Author

Thanks for the quick answer but i'm not sure that it fits my request.

I think that the only way to answer my needs is to modify the source code of the composant tFileFetch.

Indeed the major problem is the fact that the number of parameters will change for each file.

Hence the easiest way to solve the problem would be for each row (each file) to read a file (delimiter file for example) in which the parameters are written, hence the number of parameter can change each time.

 

Sorry if i was not clear

Anonymous
Not applicable

Ok, maybe this will help. I have set up a tRestClient to send a file to an API like this.....

 

0695b00000QFqI6AAL.pngThis is configured for the API I am using.....which will no doubt be different to yours. Seeing the API specification may help. But what I am doing is reading a file as a byte array, storing it in the globalMap and then using it in the tRestClient as above. The rest of the job looks like this....

 

0695b00000QFqJiAAL.pngIf you want to send multiple files with different parameters you can either use something similar, wrap it in a child job and call it from a main job that will gather the params then send them to the child job. Or you could extrapolate from the above adding a tLoop. You shouldn't need to modify the tFileFetch code for this.

RGrahams1634
Contributor
Contributor
Author

Thanks for the answer,

I tried to setup my job as shown in your example, however i have trouble understanding the purpose of the tJavaFlex composant.

I don't understand what I'm supposed to do with this one.

 

Thanks again for your help!

RGrahams1634
Contributor
Contributor
Author

Besides I have an other error, when I try to send my request the job can't compile and this the the displayed message:

"The method param(String,String) in the type Form is not applicable for the arguments(String,Object)"

If I change "globalMap.get("file")" to "globalMap.get("file").toString()" the request is sent but I get the following error:

"415 unsupported media type"

 

(I try to send a pdf file and the parameters must be given in Multipart/Form-data)