Content Disposition Header - BloomReach Experience - Open Source CMS

This article covers a Hippo CMS version 10. There's an updated version available that covers our most recent release.

22-05-2015

Content Disposition Header

The BinariesServlet can add the Content-Disposition header field to force downloaded files to be treated as an attachment with a valid file name by the browser. For example, if properly set, the header can be like this example:

Content-Disposition: attachment; filename=genome.jpeg

For the details of "Content-Disposition" header, you can refer to http://en.wikipedia.org/wiki/MIME#Content-Disposition.

MIME type configuration for BinariesServlet in web.xml

To configure which MIME types to enable content disposition headers, set the contentDispositionContentTypes init param in the web.xml in which this servlet is defined. When the BinariesServlet tries to serve a jcr data, it reads jcr:mimeType property. So, if the mimeType property value is found in the contentDispositionContentTypes configuration, then the data will be written with Content-Disposition header. For example:

<init-param>
  <param-name>contentDispositionContentTypes
  </param-name>
  <param-value>
         application/pdf,
         application/rtf,
         application/excel

  </param-value>
</init-param>

In the above init param configuration, you can also set glob style configurations such as */* or application/* like the following example:

<init-param>
  <param-name>contentDispositionContentTypes
  </param-name>
  <param-value>
         application/*

  </param-value>
</init-param>

JCR property name configuration

You can configure the JCR property to get the file name from. When the BinariesServlet tries to add Content-Disposition header to the response, it tries to read a jcr property for the file name by this configuration. To configure the jcr property name(s) for the file name, please set the contentDispositionFilenameProperty init param for the BinariesServlet in the web.xml. For example,

<init-param>
  <param-name>contentDispositionFilenameProperty
  </param-name>
  <param-value>demosite:filename
  </param-value>
</init-param>

Also, you can set multiple property names in the above init parameters. If multiple property names are set, then the first read jcr property will be chosen. For example,

<init-param>
  <param-name>contentDispositionFilenameProperty
  </param-name>
  <param-value>
         demosite:filename,
         demosite:attachmentname

  </param-value>
</init-param>

If any jcr property configured above is not found, then the Content-Disposition header will not contain filename value like this:

Appendix: File name encoding issue

The file name value in Content-Disposition header is automatically encoded for each browser. For normal standard browsers, the file name is encoded by the standard MIME encoding mechanism. (e.g. "=?iso-8859-1?Q?=A1Hola,_se=F1or!?=") However, for Microsoft Internet Explorer or Opera browser, the file name is URL-encoded for proper display.

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?