The Examples sample application demonstrates this kind of functionality (see the File Library demo). This sample application is included with the Windows installer, and can also be downloaded from here.
The demo makes use of the Callable Service plug-in which provides (among other things) the functionality for retrieving an image from the database using a URL, see the template's documentation page.
I hope this is what you're looking for.
For best results, use the Firefox browser..