Talend Connect
Virtual Summit
JOIN US!
And visit the Customer
& Community Lounge.
May 27-28, wherever you are.

tfilefetch and file extension

Highlighted
One Star

tfilefetch and file extension

Hi,
is there a way to get the file extension (.jpeg, .gif, .bmp for exemple) of a file fetched with a tfilefetch component ?
Thanks
Regards
Highlighted
One Star

Re: tfilefetch and file extension

Hi
You can't get extension from tfilefetch directly.
But you may save it into local disk and use tFileProperties to get extension.
Regards,
Pedro
Highlighted
One Star

Re: tfilefetch and file extension

tFileProperties gives :
- abs_path
- dirname
- basename
- mode_string
- size
- mtime
- mtime_string

==> where is the file extension property please ?
Regards
Highlighted
One Star

Re: tfilefetch and file extension

Hi
Link tFileProperties with tMap.
Set expression of basename.
Get extension at the right of "." .
row1.basename.substring(StringHandling.INDEX(row1.basename,".")+1)

Regards,
Pedro
Highlighted
One Star

Re: tfilefetch and file extension

I dont think it works, because the file name is defined in the tFileFetch component (property "destination Filename"), it is not fetched directly from the URI....
I would have be nice if this "destination filename" property was not mandatory, so the file extension would have been fetched from the URI...
Regards
Highlighted
One Star

Re: tfilefetch and file extension

Hi,
You can create an arborescence depending on your URI (checkbox). I don't know if your URIs have different arborescence, but if not you could use it to get the name of the file. Furthermore I don't know how your job is designed, but you could also try to put your URI in a context variable and use this context to get what you want. Can you post a screenshot of your job?
Highlighted
One Star

Re: tfilefetch and file extension

Try to fetch for example : http://gallica.bnf.fr/ark:/12148/btv1b22002053/f2.thumbnail
and automatically find out its extension (.jpg ? .gif ? .pdf ?)....
Regards
Highlighted
One Star

Re: tfilefetch and file extension

How do you get your URI? If your URI comes from a context variable, it's quite simple to get the extension by using row.substring(context.myvariable.lastIndexOf('.')).
Highlighted
One Star

Re: tfilefetch and file extension

Hi,
This is not as easy as it might seem in my opinion. Having a URI with an extension like .jsp doesn't mean the file you receive is of type jsp (whatever that may be), it could as well be an image that is send back. (How should the job know that the URI "http://www.talendforge.org/forum/viewtopic.php?id=22515" returns an HTML page for example?)
I don't know how to solve this, it's just that I don't think just looking for a . in a URI is enough to really solve this problem.
Maybe interpretation of the retrieved content is necessary to determine content type and therefor a possible extension, I don't know...
Best regards,
Arno
Highlighted
One Star

Re: tfilefetch and file extension

Hi,
Obviously it depends on what you are looking for. So what's the use of the job, It will help.
Highlighted
One Star

Re: tfilefetch and file extension

I dont understand your question, I think all is in previous posts....
The aim of my job is very simple: fetch a file from an URI (see URI example in previous post) and get the extension of the file (pdf or jpeg for example).
Regards
Highlighted
One Star

Re: tfilefetch and file extension

String fileName = input_row.fileName;
globalMap.put("fileName", row1.fileName);

if (row1.fileName.startsWith("Sample")){
System.out.println((String)row1.fileName);
}
I'm using this code to get the excel file and convert it to pdf.
Now I wanted to get all the xlsx file in my directory by not using the filename of the excel file but by it's file type. Do you have any idea?
Thanks!

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog