Six Stars

Filefetch to post to a rest multipart/mixed service to mimic Curl -X POST - F

Hi,

 

I need to communicate with an Rest API which expects a json message and binary file. The provided the following example:

curl -v -X POST -u "<system-account>:<password>" --header "X-REQUEST-ID: $_REQUEST_ID" --header "Content-Type: multipart/mixed" -F "request={\"bumId\":\"$_UUID\",\"fileType\":\"imageFile\"};type=application/json" -F "file=@image1.pdf" "https://test-api.XXXXXXX/v2/files"

 

Anybody a suggestion on how to mimic this in Talend? I have been trying with FileFetch and TRestClient.

 

curl1.PNGcomponent settingscurl2.PNGadvanced settingsSo far my results where a 500 error and no details.

4 REPLIES
Fifteen Stars

Re: Filefetch to post to a rest multipart/mixed service to mimic Curl -X POST - F

Unfortunately curl examples are not always that helpful. Did they give any other examples? One of the things you have probably got to do is to sort out the authentication. Your username and password will likely need to be converted

 

 

String userauth = "system-account" + ":" + "password";
String basicAuth = "Basic " + new String(new Base64().encode(userauth.getBytes()));
context.Authentication = basicAuth;

Do the above in a tJava (if you are not already) and then use the Authorization header as you are showing. Maybe you are doing that already, but if you aren't you should try it.

 

You appear to be using a X-BW-REQUEST-ID header instead of a X-REQUEST-ID. Why is that?

 

I'm not sure why you have the destination filename populated with a value saying "response.json". This looks incorrect, but I would expect a different error if that caused it fail.

 

The filename param looks like it is not required.

 

Unfortunately working with services without being able to try it yourself can be incredibly hard. But maybe I have given you something to think about. Good luck

 

 

Rilhia Solutions
Six Stars

Re: Filefetch to post to a rest multipart/mixed service to mimic Curl -X POST - F

Hi Rahl,

Thanks for your quick reply.
Authentication do I have sorted and working.
The difference in header was a mistake in the curl example, so I have that one fixed also and it is an optional header.
The respone.json removing the directory before the name made no difference, but I agree that would have given an error later in the process.
Any more thougths?

Kind regards
Fifteen Stars

Re: Filefetch to post to a rest multipart/mixed service to mimic Curl -X POST - F

I can't tell you how to configure as I would need to be able to try it myself. Web services are notoriously hard to debug remotely. But you could try testing the REST service out using another tool (I use Advanced REST Client for Chrome). This way you can try out your configuration outside of Talend until you get it right (and it can't fail because of a badly configured job) and then transfer that known configuration to your Talend job

Rilhia Solutions
Six Stars

Re: Filefetch to post to a rest multipart/mixed service to mimic Curl -X POST - F

Hi,

 

That is indeed a good route to follow when you run into troubles with webservices and it was also the route I followed in this case. I used SOAPui after the initial testing with the curl examples.

I will keep trying to get this to wor, thanks for your help.