Server

HOWTO: Change the Default Document Type When Importing a File in the Nuxeo Platform?

Updated: March 18, 2024

In this how-to, importing a file can correspond to using the drag and drop, using the Import button, or adding a file from Nuxeo Drive or a WebDAV drive.

When we drag and drop a file on a folder or workspace, a new document of type (File, Image, Picture, Contract...) is automatically created depending on the MIME Type and file extension. For example, dragging a .png file creates a Picture.

The mechanism to create a Nuxeo document with an import is tight to the plugins extension point from the FileManager service.

According to the MIME type of the file you try to import, a specific plugin will be called. And most of the time, it's the DefaultFileImporter plugin that will be used.

So, to create a document of your own type, you have to set the docType attribute when overwriting the default contribution. In this example, uploading a MS Word or a PDF document (.doc, .docx and .pdf) will automatically create a new Contract document:

<require>org.nuxeo.ecm.platform.picture.filemanager.contrib</require>

<extension target="org.nuxeo.ecm.platform.filemanager.service.FileManagerService" point="plugins">
  <plugin class="org.nuxeo.ecm.platform.filemanager.service.extension.DefaultFileImporter" name="ContractImporter" order="1" docType="Contract">
      <filter>application/msword</filter>
      <filter>application/vnd.openxmlformats-officedocument.wordprocessingml.document</filter>
      <filter>application/pdf</filter>
  </plugin>

  <plugin class="org.nuxeo.ecm.platform.filemanager.service.extension.DefaultFileImporter" name="DefaultFileImporter" order="100">
    <filter>.*</filter>
  </plugin>
</extension>

It is necessary to pay attention to the following settings:

  • Order attribute: Indicates the order to load the plugin. Nuxeo starts loading the highest number first. The lowest at the end, so using 1 as order your configuration prevails in case of coincidence.
  • DocType attribute: Indicates the type of document to generate. In this case, a Contract type document
  • Tags filter: Define the types

contract.png
contract.png

Going Further

This mechanism is also valid with any document type inherited from File, as Picture, Audio or Video.

Learn more
DAM Configuration video on Hyland University: Learn how to type a file as Picture according to its file extension.