xpages File Download control - open instead of save?

1.5k Views Asked by At

When you click on the link for an attachment in the File Download control in XPiNC, you are promoted to save the attachment. Is it possible to configure the File Download control to open the attachment directly instead of prompting the user to save it? We're using 8.5.2 FP3.

2

There are 2 best solutions below

6
On

I haven't used the file download control or XPINC, but it is definitely possible to make your xpage or view control open an attachment directly. This method bypasses the download control.

Please see this post from Stephan Wissel: http://www.wissel.net/blog/d6plinks/SHWL-86QKNM, which gives you some SSJS that you can use to build the URL. You can use it in the onClick method of a button. You are essentially duplicating the functionality of the download control in a way that does what you want it to do.

If you want to do the same thing from a view control, then see this post: http://notesspeak.blogspot.com/2013/02/how-to-launch-attachment-from-view.html

Note that different browsers behave slightly differently but it works in all the majors.


Michael, Here is code I used:

    var unid = rowValue.getUniversalID()
    var url = getAttachmentURL(unid, "storetransfer.pdf", "Testing//test.nsf")
    url = "/" + url + ";"
    view.postScript("window.open('" + url + "', '_blank', 'height=120,width=650,top=10,left=10,resizable=yes');");

I did modify Stephan's code a bit since my data is in a different NSF than my code. You probably know this but the view.postScript allows you to call clientside javascript from SSJS. It always is the last thing to run, hence the name. This is the same code from the Notesin9 video mentioned in the comments. I just tested this and it works like I think you want, but in firefox it does try to block the popup, and then has to push "open". Hope this helps.

1
On

Handling of an "attachment" is primarily done by the Browser (XPiNC being a firefox browser inside Notes). If for example, a PDF plugin is installed in the browser and the servers sends the corresponding "application/pdf" mime-type with the file, the browser uses that plugin to display the file. The correlation between mime-type and plugin or external application in the browser is something the server/webapplication can not influence.

What you can do on the server side is sending the mime-type "application/octet-stream" instead of the one corresonding to the file type, causing the browser to display the "Select application or download" dialog. So in Xpages, you would have to redirect the download through a XPage, where you set the corresponding HTTP Headers as shown in Set cache headers on an XPage and How to force PDF files to open in browser?