Hi,

Thanks for Apache Tika! Its a great project.

I'm trying to add a custom mime type. I've seen solutions that involve
writing a custom-mimetypes.xml file, but I'd really prefer to add my
custom type programmatically. Mostly this is because the magic bytes for
the file format are already defined elsewhere in code (which I'd prefer
not to duplicate), and I also want to leave the possibility open for
user-defined mime types at runtime.

I'm running 1.7 and doing detection like this:

TikaConfig config = TikaConfig.getDefaultConfig();
Detector detector = config.getDetector();
TikaInputStream stream = TikaInputStream.get(in);
Metadata metadata = new Metadata();
MediaType mediatype = detector.detect(stream, metadata);
System.out.println(mediatype.toString());

And this works great for my needs.

Instead of getting the Detector through the TikaConfig, I've tried
instantiating a new MagicDetector with the desired byte pattern and
MediaType, grabbing a DefaultDetector, and adding my new MagicDetector
to the DefaultDetector's getDetectors() List, and then performing
detection. Unfortunately this doesn't appear to make any difference.

Is there another way to add the custom mime type via a programmatic
interface?

silverchange

Reply via email to