logo

Upload Image Resources from The Web

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:

  • Detaches the uploaded image to the server's file system.
  • Creates a Base64 encoded representation of the image in a text file.
  • Incorporates this text file in to an XML file that is ready to be imported.
  • Imports the newly created XML (DXL) in to the database.


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".

Feedback

  1. Ok, but why?

    It's always nice to see how new technologies can be leveraged to acheive something, and this looks like a good example of how to use DXL to alter parts of a DB's design.

    Now for the 'why?'. I've always implemented image resources as a seperate DB, as the image resources design option was introduce in r5 (or was it 4.6) and I've been doing this longer than that. Resources as a DB have always seemed better as you have full control through the ACL and roles to define how and who manipulates the resources. Also, the resources can be plain text or binary depending on your need.

    Anyone know if there are performance implications to this approach versus image resources? If you set the view to only recalculate periodically, I'm not sure there is one.

      • avatar
      • Mark Ambler
      • Wed 5 Dec 2001

      learning experience

      Built this for more of a learning experience than anything else (get familiar with the DXLToolkit API, DXL syntax etc...). Maybe if a site had already commited to using the img resources from the design of the database it might be easier to set this up rather than change all the img resource tags to reflect a view/doc/file (only if the images were going to change on a periodic basis i.e. by a web admin).

      Show the rest of this thread

    1. Re: Ok, but why?

      Wish I found this a while ago. This to me seems really really great because I have had a problem whereby if you use attachments they are not cached by the browser.

      Basically when a server hands out an attachment in a document it doesn't send out the Last Modified date and therefore the browser has to get it every time.

      The only way I could get the browser to cache was to use Image Resources. But alas as a result only designers could change the images which would be a big problem for many of the sites I've developed.

  2. Related topic - solution to get image dimensions

    If you're attaching images (as resources or plain old attachments) you might also find the code here:

    http://www.martinscott.com/Site/DesignLibrary.nsf/0/8a383bb493fe7657852567160065 cf1d?OpenDocument

    useful in order to get the dimensions of the particular image in question.

  3. Can this be done using an attachment in an rtf?

    Hi Jake,

    Very interesting article. I need to do something similiar, but of course slightly different! I need to detach .gif files from created documents and import them as image resources programatically. Unfortunately, this is a client only application. Any ideas greatly appreciated!

    Niall.

  4. yes

    could you tell me known about DXLtools.jar

    • avatar
    • H
    • Thu 31 Mar 2005

    You star!

    Hey Jake. You absolute diamond geezer! Bless them, but I can't find DXLTools.jar on the IBM website. I can find lots of documentation showing me how to use and links (that don't work) pointing to where to download it. I should have just come here first off. Ta again for prevailing!

      • avatar
      • Andre Guirard
      • Tue 31 May 2005

      Re: You star!

      Now that XML processing capabilities are available in LotusScript, it's probably time to translate this into LS to provide a platform-independent version.

  5. THE IMAGE IS NOT IN IMAGE RESOURCE

    Hello.. I made the sample... but.. the image is not in image resource... the image are in other view. When I said on other form create image resource, it is not show the image. What happend here?

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:



Navigate other articles in the category "Java"

« Previous Article Next Article »
Multiple Threads in Notes Agents   Sending HTML mail via SMTP part 1

About This Article

Author: Jake Howlett
Category: Java
Hat Tip: Mark Ambler
Keywords: image; resource; DXL;

Attachments

ImgImport.zip (1575 Kbytes)

Options

Feedback
Print Friendly

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »