I need to write a routine that automatically imports a csv file containing simple text eg title, firstname, surname and then at the end it contains an image in BLOB format.
Ive done a few searches but everything seems to link directly to oracle using LEConnect for BLOB’s. Is there any way to do this in lotuscript or failing that in JAVA? Does anybody have any examples I can look at ?
Subject: SOLUTION
I just got it working code below…
Const DIRECTORY = "C:\Documents and Settings\c00501\My Documents\Projects\CAS\Import\"
row = 2
Do While Not xlSheet.cells(row, 1).value = ""
' GENERATE AN IMPORT LOG FOR EACH LINE
Set iLog = thisDB.CreateDocument
iLog.Form = "importLog"
iLog.appTitle = xlSheet.cells(row, 1).value
iLog.appForenames = xlSheet.cells(row, 2).value
iLog.appSurname = xlSheet.cells(row, 3).value
iLog.imageName = xlSheet.cells(row, 87).value
Dim stream As notesStream
Dim notesMIMEEntity As notesMIMEEntity
’ CREATE THE MIME ENTITY
session.ConvertMIME = False
Set notesMIMEEntity = iLog.CreateMIMEEntity( "imageBinary" )
If Not(notesMIMEEntity Is Nothing) Then
Set header = notesMIMEEntity.CreateHeader("Subject")
Call header.SetHeaderVal("MIME Applicant Image File")
Set stream = session.CreateStream
Call stream.WriteText(xlSheet.cells(row, 88).value)
Call notesMIMEEntity.SetContentFromText (stream, "text/plain;charset=UTF-8", ENC_BASE64)
End If
session.ConvertMIME = True
’ CREATE THE BINARY OUTPUT FILE
Dim outStream As notesStream
outPath = DIRECTORY & "/" & xlSheet.cells(row, 87).value
Set outStream = session.CreateStream
If outStream.Open(outPath, "binary") Then
Call notesMIMEEntity.GetContentAsBytes(outStream ,True )
End If
Call Stream.Close
Call outStream.Close
Call iLog.Save(True, True)
row = row + 1
Loop
Subject: RE: csv with BLOB image
CSV is a text format. How can it contain a BLOB, which is binary?Does the file only contain one “row”?
For the binary data to get written into an RDB by the LC LSX, you will need to get it into an LCStream by itself. I think you’ll have to write it to a file, then read the file contents with the File connector. So you’ll have to read the original file with something other than LC, since there’s no connector that understands a mix of text and binary.
Subject: RE: csv with BLOB image
Hi Andre,
Thanks for the response.
Its a file we are getting sent containing persons details. The file is a csv and if you open it in excel for example it contains a cell for title, firstname etc then a huge field with the binary data in. Ive spoken to the company that creates the file and it is created in oracle with the image as a BLOB data type.
The example ive been sent contains two test records
Subject: RE: csv with BLOB image
It may be a BLOB in Oracle, but it’s probably a Base64-encoded file in the CSV. Depending on the image type, you may be able to import it directly using DXL. Otherwise, you’re in for a bit of a ride. Decoding the Base64 value can be done with a NotesMIMEEntity, and you can save the decoded binary to disk using Open File and Put or NotesStream and Write. That’s if the encoding is compatible, of course. You can then attach the file to the document. Importing the file to a rich text field, say, would be a whole 'nother matter – you’d need to visit the C API or use a third-party tool (like the Midas Rich Text LSX from http://www.geniisoft.com ).
Subject: RE: csv with BLOB image
Hi Stan,
Thanks for the response. Your absolutly spot-on. Ive done a bit of digging and it is a Base64-encoded file in the CSV. Im just about to have a go at getting the NotesMIMEEntity and doing it that way.
Am I right in thinking that I would have to read the record into a notesRichTextItem as text and then call the GetMIMEEntity and decodeContent before opening a binary file and writing to it ?