[Q&A Friday] Enabling Preview For Document Attachments

Fri 04 January 2013 By Laurent Doguin

Enabling preview for attachments Enabling preview for attachments

Today we have a question about document preview. The default behaviour of the JSF app only gives you the preview of the main file. You don't have preview for the attachments. But the good news is that technically, it relies on a REST API, so it's pretty easy to call. Here's an example from the default preview window:


To understand how this works, let's take a look at the documentation. Since it's quite old, it uses the restlet. So in Nuxeo Explorer you have to search for the restlet extension point.

The format of the URL is as follow:


So I have to find the right fieldPath to access my attachment. It's stored in the schema files, as the first element of the files list (usual xpath would be files:files/1/file). Here's what it looks like:

Note that the slash in the fieldPath has to be replaced by a dash.

Now you can have a preview of any file. The choice is up to you as to where/how to display it. I like the fancybox. I think it looks great and it's really easy to set up. Here's just a quick example:

<nxu:inputList value="#{currentDocument.files.files}" id="files_input" model="model">
<a4j:commandLink ajaxSingle="true" ignoreDupResponses="true" requestDelay="100"

Also something that you need to know: the HTML preview of any file is computed using converters. So if for some reason you cannot preview a file, you need to make sure there's an HTML converter for it. We try to have as many as possible by default, but some file types are not covered (usually it's because they are proprietary, undocumented file formats).

Category: Product & Development
Tagged: Document Management, Q&A