Attachment URLs in XPages
In classic Domino applications directly addressing attachments is well known and simple. Your URL has the format:
While this will continue to work on the Domino server for the forseeable future you want to learn about the XPages syntax. The very obvious reason: the classic Domino URL doesn't work in the Notes client (XPiNC) and you want to make your applications work cross-platform don't you? Also we don't know what additional options handling attachments via XPages might bring in the future. the syntax is a litte more complex.:
A few remarks:
As usual YMMV
http(s)://[yourserver]/[application.nsf]/[viewname|0]/[UNID| ViewKey]/$File/[AttachmentName]?Open
While this will continue to work on the Domino server for the forseeable future you want to learn about the XPages syntax. The very obvious reason: the classic Domino URL doesn't work in the Notes client (XPiNC) and you want to make your applications work cross-platform don't you? Also we don't know what additional options handling attachments via XPages might bring in the future. the syntax is a litte more complex.:
http(s)://[yourserver]/[application.nsf] /xsp/.ibmmodres/domino/OpenAttachment/ [application.nsf]/[UNID|/$File/[AttachmentName]?Open
A few remarks:
- The URL contains the application location twice. From my tests it looks like the
/__[ReplicaID].nsf/
doesn't work for here. I haven't tested what happens when you specify 2 different applications in the front and the back - Since there is no view involved in the URL addressing attachments using an attachment key won't work. You have to use the UNID. This requires extra care when you build applications where the attachment URL is supposed to be shared (like send in a chat or an eMail). Deleting a document and recreating with an updated attachment will alter the URL. So ou want to cater for that case with a specific XPage rather than a raw URL.
- When you attachment is stored inside a RT field (e.g. using the upload control where you target a field) you can replace "/$File/" with the field name e.g. "/Body/"
-
function getAttachmentURL (docID :java. lang. String , attachmentName :java. lang. String ) {
-
var base = getBaseURL ( ) ;
-
var middle = "/xsp/.ibmmodres/domino/OpenAttachment" ;
-
if (base. substr ( 0 , 4 ) == "/xsp" ) {
-
middle += base. substr ( 4 ) ;
-
} else {
-
middle += base ;
-
}
-
var result = base + middle + "/" + docID + "/$File/" + attachmentName + "?Open" ;
-
return result ;
-
}
-
-
function getBaseURL ( ) {
-
var curURL = context. getUrl ( ) ;
-
var curAdr = curURL. getAddress ( ) ;
-
var rel = curURL. getSiteRelativeAddress (context ) ;
-
var step1 = curAdr. substr ( 0 ,curAdr. indexOf (rel ) ) ;
-
-
// Now cut off the http
-
var step2 = step1. substr (step1. indexOf ( "//" ) + 2 ) ;
-
var result = step2. substr (step2. indexOf ( "/" ) ) ;
-
return result ;
-
-
}
Posted by Stephan H Wissel on 24 June 2010 | Comments (1a) | categories: XPages