Four Stars

Uploading a file to tREST API

Hello,

 

I am calling a REST API which has multiple input parameters and one of the input parameters is a file (CSV). 

How can I load a file using tREST component?

1 ACCEPTED SOLUTION

Accepted Solutions
Fifteen Stars

Re: Uploading a file to tREST API

Your settings look fine. 

 

The defaultfilename.txt comes from some default code for the tFileFetch to set a destination filename. You could maybe try ticking "Use cache to save resource" as a workaround (if that is causing this, it is a bug).

 

This is really difficult to resolve without having access to the service. Documentation and implementations of services can vary wildly and you really need to treat using them with Talend like a debugging exercise. If I were you I would try this method demonstrated here: http://talend.nl/talend-tech-tip-calling-a-rest-service-for-file-upload/

 

Rilhia Solutions
9 REPLIES
Fifteen Stars

Re: Uploading a file to tREST API

It would help to see the API specification for this. But you may be able to just use the tFileFetch (https://help.talend.com/reader/MjIZDoU6r0vLbCpGh5GAcg/F4QsQrja9IQEa_kKqmBfNQ). Don't be put off by the name, this component can be used to both download files and upload them.

Rilhia Solutions
Four Stars

Re: Uploading a file to tREST API

Thanks for the reply. However i have to pass a bunch of parameters in the body of the request as shown in the postman screenshot below. How do you propose I do that using tFileFetch? Any example to share perhaps?

Fifteen Stars

Re: Uploading a file to tREST API

The tFileFetch sends a multipart message in the body. This contains the file and the other parameters. It is unfortunate that I cannot try this out as I do not have access to your service. Web services are notoriously tricky to work out without having access to them. But have you tried setting our parameters in the parameters section of the tFileFetch?

Rilhia Solutions
Four Stars

Re: Uploading a file to tREST API

I tried with the tFileFetch component and it seems to be hitting the service but returns with the below error message. I get the header of the response back but not the body and I dont know from where its trying to pick the "\defaultfilename.txt". Also, if I try to run the component the second time it fails. And if I change the file name to something else it runs again with the below message. Do you know whats going on here. 

"Starting job Copy_of_testRestAPI at 15:35 27/02/2018.

[statistics] connecting to socket on port 3694
[statistics] connected
Status Line: HTTP/1.1 200 OK
*** Response Header ***
Server: nginx
Date: Tue, 27 Feb 2018 20:35:45 GMT
Content-Type: application/json
Content-Length: 612
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: Express
Vary: Origin
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=86400; includeSubDomains
Exception in component tFileFetch_1 (Copy_of_testRestAPI)
java.io.FileNotFoundException: \defaultfilename.txt (Access is denied)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at amgen_data_validations.copy_of_testrestapi_0_1.Copy_of_testRestAPI.tFileFetch_1Process(Copy_of_testRestAPI.java:618)
at amgen_data_validations.copy_of_testrestapi_0_1.Copy_of_testRestAPI.runJobInTOS(Copy_of_testRestAPI.java:890)
at amgen_data_validations.copy_of_testrestapi_0_1.Copy_of_testRestAPI.main(Copy_of_testRestAPI.java:733)
[statistics] disconnected"

Fifteen Stars

Re: Uploading a file to tREST API

This looks like a file/folder permission issue. Have you tried moving the file to a location where everyone has permission?

Rilhia Solutions
Four Stars

Re: Uploading a file to tREST API

yes the file is in "c://" with read write access to everyone. 

Also, like I said if I change the name of the file it works fine and then in the above case it got the header back but not the body. 

Four Stars

Re: Uploading a file to tREST API

Attaching my settings from tFileFetch. Does this seem to be right? Any pointers?

Fifteen Stars

Re: Uploading a file to tREST API

Your settings look fine. 

 

The defaultfilename.txt comes from some default code for the tFileFetch to set a destination filename. You could maybe try ticking "Use cache to save resource" as a workaround (if that is causing this, it is a bug).

 

This is really difficult to resolve without having access to the service. Documentation and implementations of services can vary wildly and you really need to treat using them with Talend like a debugging exercise. If I were you I would try this method demonstrated here: http://talend.nl/talend-tech-tip-calling-a-rest-service-for-file-upload/

 

Rilhia Solutions
Four Stars

Re: Uploading a file to tREST API

Ultimately I did write the JAVA code to call the API. Which is not the ideal way to do it. So going to close this topic and have opened another one to see if anyone from Talend can address it.