tfilefetch and file extension

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
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
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
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
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?
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
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('.')).
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
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.
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
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!