Sametime Business Cards … Who Wants To Upload Their Picture?
Following a post I wrote a few weeks ago about Sametime Pictures and another here about a security issue with the Sametime Business Card feature, someone asked via the comments if I could post my code that I used to resize and upload the pictures in our Domino Directory. The short answer was “sorry, no”. For various reasons I cannot post the code of the agent that I wrote for my company because it does various other things and even pulls data from other sources that wouldn’t matter much to anyone else but us.
However, I gave this some thought and I decided to write a small agent that can be called by employees from the Actions menu of the Domino Directory to upload their own picture. And, since I said that I’d try to write a blog post about this, here’s the result.
Before You Start – You Need To Setup The Business Card Feature!
Before you start thinking about using this agent to allow people to upload their own picture into your Domino Directory, you need to make sure that your Sametime server is configured correctly to pull the pictures from the right place using the right field name and data type. I won’t go into details here because Lotus has written Technote #1244204 on the matter which I used to setup our own Sametime 7.5 server to “see” the jpegPhoto field correctly. Basically speaking, you need to add “:binary” to the photo field of the Business Card configuration screen … which is weird if you ask me.
Keep in mind that we have not upgraded our servers to Sametime 8.5 yet (way too scary for now … but we might go with the “classic” edition later down the road) so you’ll need to look somewhere else for the “how to make sure it’s configured properly” if you are using Sametime 8.5 servers.
The Good Stuff: A Bit More About The Agent
Well, right away, I need to mention that the agent is in Java. Yep, Java. Scary isn’t it? It’s in Java because that programming language has classes that can resize an image built right into it. And because of that, it means that employees don’t need to install anything on their computers to resize the 10 mega-pixel picture they are trying to upload.
Also keep in mind that I’m very rusty when it comes to Java so, although the agent does the trick for me, feel free to revamp it to make it better. In fact, you might find the code a bit “procedural” and not very fancy in terms of “object oriented-ness” but hey, it does the trick. Also, keep in mind that image resizing techniques in Java are a dime a dozen on the Intertubes and I used the most basic method I could find (you can read more about the method here on Java.net but I tweaked it to suit my needs).
How to Use The Agent
Well, first and foremost, you need to download the code below and create the Java agent in your own Domino Directory that can be called from the “Actions” menu. I called my agent “Import Picture”.
Once you have created the agent, any employee that opens the Domino Directory can select his/her name can then click on “Actions -> Import Picture” (or whatever name you gave the agent). When the agent starts, it does a check to make sure that the employee has only 1 “Person” selected but it does not check to make sure that it’s the employee’s very own document that’s selected. So, “buyer beware”: they’ll get a nice error if they try to upload a funny picture into someone else person document (unless you’ve set your Domino Directory ACL wrong and anybody can modify everyone else person doc in there … if that’s the case, you have bigger things to worry about than someone uploading a picture of someone else passed out drunk on his lawn).
Anyhow, if the employee has a person document selected, they’ll then be prompted to select a file with a “JPG” extension from their hard drive. Yes, a file with a “JPG” extension. Not “JPEG”. Not “GIF”. Not “BMP”. I need a ”JPG” file. Sure, I could have updated the code to work around this but I wanted to keep it simple.
It’s important to note that the picture that the employee selects has to be on their own computer (or on a network share that they have “write” access to) because the code will create a resized copy in the same location as the original file. In other words: they’ll get another nice error if they selected a picture on a network share that they only have “read” access to.
Once the jpg file is selected, the code will kick-in and create a copy of the selected image resized to a width of 100 pixels (it will keep the aspect ratio). You can modify the code to resize them smaller or bigger but 100 pixels seems a good compromise between the “look & feel” of the Sametime Business Cards vs. how much more data the Domino Directory has to store. In fact, I think that the Business Cards feature re-downsizes the pictures to 90 pixels but I could be wrong.
Once the image is resized, the code checks to make sure that the resized picture is not bigger than 20 000 bytes because that kills the Sametime Business Card feature (read more on that topic on the excellent blog of Mr. Vladimir Kocjancic in his post here).
At that point, if everything is ok, the resized picture gets inserted into the hidden “jpegPhoto” field on the person document. That field is not visible on the UI so employees cannot “see” the results when they open their own person document in the Domino Directory. However, they can right-click on their entry in their Sametime Contact list and select “Refresh Business Card” to see their new picture.
So, Where’s the Beef … err, Where’s The Code?
Well, here you go… the code of the agent is attached below. Simply click on it to download the code to your hard drive. Once you have it, import it into a new Java agent that can be called from the Actions menu in your Domino Directory and test it out in your test environment first before moving this production.

The Usual Disclaimers …
Well, as usual, I have to do a bit of CYA: if you decide to use this code, test it in your test environment 1st. It works for me but you need to make sure it works fine in your own environment before moving it production.
Also, if you are a Java guru, please review the code to see if you can improve it. And if you can: please post the updated code on your own blog (you are blogging right?).
Parting Words …
Oddly enough, this is only blog post in April (so far) … it’s been an insanely busy month (which included a business trip to New Jersey). I have no idea where time went but I haven’t been able to keep up with everything so blogging took a back seat up to this weekend. Hopefully, things will quiet down and I’ll be able to post things more often.
Thanks for reading!
Marc