Search code examples
xpages

Override Content Disposition Type for Attachments Opened Through xPages URLs


Is there a way to override the content disposition header for an attachment opened through an xPage URL? I am attempting to open attachments/pdf's in the browser as opposed to the default which is to download/save.

This question was also asked on Wissel's site by Mark Leusink, but I couldn't find an answer.


Solution

  • There are two approaches you can take:

    • Use an XAgent to read the attachment stream instead of linking to the attachment directly. There you can use the following to overwrite attachment/inline and file name.
    response.setContentType("text/xml");
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("content-disposition", "inline; Filename=invoice.pdf");
    
    • Be nice to your admin and use a web site rule to overwrite the HTTP header for your attachment urls. No code change in your application required and can be on a per application base

    HTH :-) stw