OpenNTF.org - Export all GIF and JPG FileRes
    Advanced
   OpenNTF Code Bin
Edit Document Code By Date > Code Document
About This Code
Brief Description:
Export all GIF and JPG FileResources from a database 
Rating:
Not Rated Yet 
Contributor:
Guido Purper 
Category:
Lotusscript 
Type:
Example Code 
Notes Version:
R6.x, R7.x 
Last Modified:
22 Jun 2007 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
This code exports all GIF / JPEG ImageResources from a given database into an existing directory.


I am using DXL, the DOMParser and 2 tempfiles, so the code is not optimized for speed.
DestinationDirectory must exist., the images as well as the tempfiles are created in DestinationDirectory.

Tried with Notes 7.0.2 but should work for Notes 6.x as well.
Don't expect an optimized code. I had to get something in place fast and for a very special need. Take the code as an example to be adapted/optimized for your needs.

Usage / Example
Dim db As NotesDatabase
Set db = New NotesDatabase( "YourServer/svr/somewhere", "database.nsf")

Call ExtractImageResources( db, "C:\temp" )
Code Attachments
 Comments
Posted by Andre Guirard on 06/21/2007 03:50:54 PMInteresting, but why the temp file?
I've done this kind of conversion, and I know you can just write the base64 text into a NotesStream directly, and then use MIME to convert it as you are already doing. The intermediate step of creating a file of base64 information seems like a pointless drag on performance.
Posted by Guido Purper on 06/22/2007 01:37:59 AMtempfiles
I know that it is possible to convert without a tempfile.
As already mentioned, the code was written for a very special purpose. I had to get results fast and the usage of tempfiles was the easiest way to get something in place.
If you have optimized code, let me konw and I will update ... or post your version here.
Posted by Andre Guirard on 06/22/2007 08:08:26 AMconverting to/from base64 without a temporary file
There's an agent in this Sandbox download: http://www-10.lotus.com/ldd/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/590c53e84b61a7c785257126004b3045?OpenDocument
named 'Extract Image Resource', which does this. The part we're discussing is the subroutine below. In your case, you would pass it TempChildNode.NodeValue as the first argument, and for the second argument a NotesStream which is already attached to the output gif or jpg file.
Sub Base64ToBinary(strBase64$, streamOut As NotesStream)
' Given a string containing base64-encoded binary data and an output stream, this
' routine converts the encoded data to binary data and writes it to the stream.
' This is especially handy for converting embedded images in a form, document,
' rich text field, or image resource design elements, into files (or just getting
' the binary data so that you can, for instance, determine the dimensions of an
' image that someone's uploaded into a web app.
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim mime As NotesMimeEntity
Dim streamIn As NotesStream
' We could do math on the ASCII codes of the characters, but that's slow in LScript.
' Instead, take advantage of the MIME conversion ability of the NotesMIMEEntity class.
Set db = session.CurrentDatabase
Set doc = db.CreateDocument
Set mime = doc.CreateMIMEEntity("Body")
Set streamIn = session.CreateStream
Call streamIn.WriteText(strBase64)
streamIn.Position = 0
Call mime.SetContentFromText(streamIn, "image/gif", ENC_BASE64)
Call mime.GetContentAsBytes(streamOut, True) ' decode as you stream out the data.
End Sub
Posted by Guido Purper on 06/22/2007 09:13:52 AMconverting to/from base64 without a temporary file
Thanks for the link to the sandbox. Great code.
If I would have known it, I would not have posted my code here....
I have tried before without tempfile but faild.
Now reading Ed's code, i understand what I did wrong :-)
I will try to update my code here next days.
Anyway, Ed's code is much better than mine !
Posted by Andre Guirard on 06/23/2007 07:54:24 AMEd's a clever fellow...
...but he's somewhat obsessed with the color blue.
Posted by Brian Green on 12/01/2007 02:10:52 PMbase64 for file resources
Thanks for this code Guido!
I needed to export file resources to disk in my openntf project. This was very similar to exporting image resources. I created a LotusScript class named FileResourceExporter. It can export image resources or file resources based on a selection formula. It's a script library in this openntf project:
http://www.openntf.org/projects/pmt.nsf/ProjectLookup/SimplePhotoAlbum
 Add your comment!