In this article I will show you a very simple way to change the name of a file when the user downloads it using the new HTML5 “download” attribute.
The download Attribute
This is unfortunately only support in Chrome so far but it is coming – the HTML5 download attribute – very simple and very effective. In the old days we had to fiddle with content-type and content-disposition to rename a file on the way out of the server – now much easier.
What we are trying to create is HTML which looks like this
<a href="/jQInX.zip" class="xspLink" download="MarkySampleDatabase"> Download the sample database - with download attribute </a>
The download=”MarkySampleDatabase” is the important part – it changes the name of the file in the a href to be “MarkySampleDatabase”
The XPages code
The following is 8.5.3 Xpage Source Code adding the download Attribute via the attr properties of the
<xp:link escape="true" text="Download the sample database - with download attribute" id="link1" value="http://demo.xomino.com/xomino/jQinX.nsf/SampleDB/jQInX.zip"> <xp:this.attrs> <xp:attr name="download" value="MarkySampleDatabase"></xp:attr> </xp:this.attrs> </xp:link>
And that is pretty much it – from the example which can be seen here there are two links both link to the sample jQinX.nsf sample database
Viewing the source shows us both links are the same…
But the one with the download attribute, downloads with a completely different name