Adding a Mime Type
Warning: Archived Page
The official documentation is at: http://docs.alfresco.com
Back to Server Configuration
- 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:
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 , 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.
If the file format for which you are adding the mimetype builds on top of one of the well-known filetypes already supported by both Alfresco and Apache Tika, you may wish to also add the mimetype to Apache Tika complete with the mimetypes hierarchy information. To do that, create a file org/apache/tika/mime/custom-mimetypes.xml and populate it with details of your mimetypes, in the FreeDesktop MIME-Info format. As an example, this what you'd add for a custom mimetype which is based on a zip file structure:
<?xml version="1.0" encoding="UTF-8"?> <mime-info> <mime-type type="application/x-my-custom-zip-format"> <_comment>My custom format which is built on top of ZIP</_comment> <glob pattern="*.myformat" /> <sub-class-of type="application/zip" /> </mime-type> </mime-info>
PS: To add mimetype custom mapping in a packaging (AMP or JAR), you should use the file: /META-INF/mimetype/mimetype-map-custom.xml.