Views
Adding a Mime Type
From alfrescowiki
Back to Server Configuration
Contents |
Introduction
- This document assumes knowledge of how to extend the repository configuration.
- There is additional reading on how to extend XML configuration files in the web client configuration documentation.
Adding additional Mime Types to the repository
By default, there are two files that currently contain mimetype definitions:
- mimetype-map.xml
- mimetype-map-openoffice.xml
These are contained within the alfresco.war->repository.jar and should not be edited directly.
Mimetype Map files
Mimetypes are defined in XML in 'mimetype-map files. These contain definitions for one or more mimetype, featuring the display name for the mimetype, and any file extensions it uses. The file is of the form:
<alfresco-config area="mimetype-map">
<config evaluator="string-compare" condition="Mimetype Map">
<mimetypes>
<mimetype mimetype="application/test" display="Example mimetype">
<extension>ex</extension>
</mimetype>
<mimetype mimetype="application/test2" display="Another example">
<extension default="true">ex2</extension>
<extension>ex3</extension>
</mimetype>
</mimetypes>
</config>
</alfresco-config>
For more advanced file type detection than offered by file extensions alone, you should consider additionally defining your Mimetype to Apache Tika, and supplying custom Mime Magic for detection. See Adding Your MIME-Type for details on how to define custom mimetypes to Tika.
Adding additional Mimetype maps - Alfresco 3.x, 4.0
Instead, of editing the core mimetype files, override the mimetypeConfigService bean in an extension file, such as <extension>/alfresco/extension/custom-services-context.xml.
<bean id="mimetypeConfigService" class="org.alfresco.config.xml.XMLConfigService" init-method="init">
<constructor-arg>
<bean class="org.alfresco.config.source.UrlConfigSource">
<constructor-arg>
<list>
<value>classpath:alfresco/mimetype/mimetype-map.xml</value>
<value>classpath:alfresco/mimetype/mimetype-map-openoffice.xml</value>
<value>classpath:alfresco/mimetype/mimetype-custom-extensions.xml</value>
</list>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
An example context file that does this is supplied in alfresco/extension/mimetype-map-extension-context.xml.sample
The UrlConfigService can load additional files such as:
- classpath:alfresco/mimetype/mimetype-custom-extensions.xml - the file is in the app server's shared classpath location
- file:/home/alfresco/conf/alfresco/mimetype/mimetype-custom-extensions.xml - the file is outside the server classpath locations
Any number of additional files can be added to the list.
Before Alfresco 4.0.1, Share did not retrieve its list of mimetypes directly from Alfresco but processes them within alfresco\site-webscripts\org\alfresco\components\form\controls\mimetype.ftl. This file either needs to be updated to include your new mimetypes, or the instructions under the bug ticket should be followed [1], or you should upgrade to 4.0.1 for the fix.
Adding additional Mimetype maps - Alfresco 4.0.1 and later
This applies to Alfresco 4.0.1 and later, and Alfresco Community builds from r33865 onwards
To make including additional Mimetype Maps easier, Alfresco 4.0.1 has changed to automatically loading extension mimetype maps that match a filename. This mirrors the extension behaviour in other areas of Alfresco.
To have your map loaded, place it into the alfresco/extension/mimetype/ directory, with a name that ends with -map.xml . An example file is provided as alfresco/extension/mimetype/mimetypes-extension-map.xml.sample . Multiple files may be included this way.