[resolved] How to Extract a files MIME type?

One Star

[resolved] How to Extract a files MIME type?

Hi I'm migrating an archived directory of files into a storage system, this system needs to have the mime type of the files inserted into its db.
I had hoped that either the tFileList or tFileProperties component would have the mime type but this is not present.
I've also tried several snippets of Java code as per http://stackoverflow.com/questions/51438/getting-a-files-mime-type-in-java, with no success.
Is there a talend component that can extract mime types? Alternately is there a piece of Java code that would do the job?
I could go down the route of parsing the extension out and using a crude lookup table but hope there is a more elegant way.
Cheers Andy
One Star

Re: [resolved] How to Extract a files MIME type?

Just worked this out;
Created new routine "mime" (Obviously needs some tidying)
"package routines;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class mime {
public static String main(String path) throws IOException {
Path source = Paths.get(path);
return Files.probeContentType(source);
Then used mime.main({path}) to get the mime_type.
This seams to work ok(only for java 7 I believe), would still be interested to hear if there is an OOB way to do this.

Calling Talend Open Studio Users

The first 100 community members completing the Open Studio survey win a $10 gift voucher.

Start the survey


Talend named a Leader.

Get your copy


Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables


How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration


Why Companies Move to the Cloud: 7 Success Stories

Learn how and why companies are moving to the Cloud

Read Now