Upload Image Resources from The Web

Jake Howlett, 5 December 2001

Category: Java; Keywords: image resource DXL

Now I like to think that when it comes to Domino I am pretty clued up on what can and can't be done. For instance, if somebody were to ask me whether I could change their application so that the images they uploaded were stored as Image Resources instead of attachments I'd say "you can't". That was until a few weeks ago when Mark Ambler contacted me and said he had an interesting topic for an article. He wasn't joking.

Apparently he was in a similar situation when a co-worker asked him if this could be done. They had designed a system that utilised the Image Resource object. Typically the customer then wanted that little bit extra and wanted to upload the images via the browser.

Mark knew enough about the DXL Toolkit to know that this should be possible with a little Java. After trying a couple of attempts he came up with something that did the job. This is what I'm about to describe.

The solution:

Before starting it's a good idea if you download the sample database. Not only does this contain all the Java code you need it also contains all the files you need. Becasue Mark has attached all the necessary files you don't actually need the DXL Toolkit. However, it is a good idea to get to know the toolkit better as this technique is only the proverbial tip of the iceberg.

The code in the agent that does all the work is not going to be covered in this article as it will take long enough just to explain how to set up the application. You could cut & paste this agent if you like or you could get to know it and make your own enhancements. Whatever you choose to do let's see what the agent actually does:



Setting up your server:

The Lotus DXL toolkit is only supported on the Win32 platform. For this reason I will assume you are setting up the application on a Win NT/2000 Server. All the files that you need to do this, referred to below, can be found in the "Using this database" document of the sample database, as I mentioned earlier.

Let's go over what's needed to set up your server, step by step.

Step 1: Setup the Notes.ini file

If you don't already have a folder used to store Java files, create one now. Detach the two files called DXLTools.jar and Base64.jar in to this folder.

In the server's Notes.ini file add (or edit) the "JavaUserClasses" variable so that it points to these files. Make sure that this is not the last line in the .ini file. The entry should look something like:

JavaUserClasses=C:\<YourJavaDir>\DXLTools.jar; C:\<YourJavaDir>\base64.jar

Step 2: Add the DXL Tools

Detach the DXLTools10.dll file to the Lotus\Domino directory or to the folder in which the Domino binaries were installed.

Now make sure that this directory is included in the server's "Path" Environment Variable, like below:

image

Step 3: Add the DTD

The XML process needs access to the Domino DTD. Detach the Domino.dtd file to the root directory of the server (C:\). If you would rather it lived somewhere else you will need to change some of the hard-coding in the agent.


Testing the setup:

Once you have completed all of the above, open the sample database in Domino Designer and find the form called "Images". Select to preview this in a browser.

image

When the form appears in the browser you should see a File Upload Control. Use this to upload a GIF or BMP image to the server.

image

Return to the database in Designer and go to the list of Image Resources. As if by magic, there should be one there with the same name as the image you just uploaded.

image


My final thoughts:

First thing that strikes me about a solution like this is that you are going to have a fight on your hands to get the server's administrators to agree to make the above changes. Then there is the fact that this is Windows only solution. Not only that but a Windows system that can soon fill with unwanted files unless they are dealt with accordingly.

Note also that I'm pretty sure I read somewhere about a limit on the number of Image Resources that can be added to a DB.

Whatever's the outcome, this is an amazing use of a mix of technologies to achieve one's goal. I only hope that we have all learned at least something from it. Personally it is a reminder that I shouldn't be so sure that something isn't "doable".