XPages has a built in feature for handling attachments called .ibmmodres.
It has (at least) the following 3 end points:
Open attachment for download in a document:
/xsp/.ibmmodres/domino/OpenAttachment/<path to database>/<UNID>/$file/<file name>
Download attachment from the temporary directory:
Open attachment (image) for inline viewing:
<path to database>/.ibmmodres/<UNID>/$file/<file name>
Please document these and any other end points that it offers.