Six Stars

How to upload files using tREST?

I am trying to use tREST to upload/update files. I could use tFileFetch. But, that supports only POST, not GET and PUT.

 

How can I pass the filename in the body and also how to pass the username/password authentication credential (the Basic authentication)?

 

Appreciate your help.

 

Thanks

 

10 REPLIES
Five Stars

Re: How to upload files using tREST?

You can use a global variable "FileName" to store the filename and then in the body just do: (String) globalMap.get("FileName")

 

To use basic authentication add a HTTP Header as follow

name: "Authorization"

value: "Basic urlEncodedText"

 

The urlEncodedText would be [user]:[password] url encoded

To get the encoded text you can run this java code in one of the online java sites as: https://www.compilejava.net/

 

import java.util.Base64;
String str;
str = "[user]:[password]";
str = Base64.getUrlEncoder().encodeToString(str.getBytes());
System.out.println("encoded value is " + str);

 

Hope it helps

 

Six Stars

Re: How to upload files using tREST?

Thanks,  dbeltritti.

I tried tREST with the settings as shown below. But its not working. Am I doing something wrong here?

I am trying to upload jpg images.

 

 

 

 

 

image.png

Five Stars

Re: How to upload files using tREST?

That will post the file path, no the actual file content. Do you want to post the actual file through a rest service?

Six Stars

Re: How to upload files using tREST?

Yes, I want to upload jpg files (want to use POST and PUT).

 

Thanks,

Employee

Re: How to upload files using tREST?

Hi,

 

     The below article is calling REST service to load a png file. It will require some custom code but this should help you to perform your task to upload image files. Could you please try it?

 

http://talend.nl/talend-tech-tip-calling-a-rest-service-for-file-upload/

 

Warm regards,

Nikhil Thampi

Six Stars

Re: How to upload files using tREST?

Nikhil, thanks for the suggestion. But this doesn't work for me. I followed the article, but it throws bunch of compilation errors even with the jars uploaded.

 

As I mentioned before, I am able to upload file using "POST" in tFileFetch. Now, I also need file "PUT" option. Are there any other options to accomplish that?

 

Appreciate the help.

Four Stars

Re: How to upload files using tREST?

You can use the tFileFetch component that allows you to download files, however in its advanced settings you can enable the "upload files" which then uploads the files. As a bonus it does it in a multi-part http post.

See more: https://help.talend.com/display/TalendComponentsReferenceGuide61EN/tFileFetch
Two Stars

Re: How to upload files using tREST?

thanks man.

Six Stars

Re: How to upload files using tREST?

Thanks, @francispandey.

 

I am actually using tFileFetch to POST a file. That works fine. However, I also need option for "PUT" method. tFileFetch supports only POST.

 

Any other suggestion?

Nine Stars

Re: How to upload files using tREST?

Im like a cUrl evangelist for the majority of web integration stuff ... so try cUrl ... you may ask yourself why ... because of this... cookies, redirection, oAuth or other types of authentication, certificates , etc etc etc...
Way more flexible!