title: Create Inline Image in a RichText Item from an Agent
body: <p>I'm trying to write an Agent which is run via an xmlhttprequest and accepts
  a UNID and a Base64 encoded image as paramater.</p>
  
  <p>What i'm up for is that the agent decodes the base64 string and writes it as an inline Image
  into a RichText Field</p>
  
  <p>I tried writing the base64 encoded string to a Stream, then creating a MimeEntity with a Child Entity and set the content from the stream,
  Then get the MimeEntity Item and Append it to the RichTextItem</p>
  
  <pre><code>.
  .
  .
  Call stream.Writetext(data)
  .
  Set body = doc.CreateMIMEEntity("RT")   
  
  
  Set header = body.CreateHeader("Content-Type") 
  Call header.SetHeaderVal("multipart/mixed")
  .
  Set child = body.CreateChildEntity() 
  Call child.Setcontentfrombytes(stream, "image/jpeg", 1727) 
  Call child.Decodecontent()
  .
  Call RT.AppendRTItem(MimeEntityItem)
  </code></pre>
  
  <p>But I end up with a 6400byte image/jpeg file
  And now i don't get any further</p>
  
  <p>Does anybody has any clues on how to get something like this working ?
  Thanks in Advance =)</p>
  
  <p>Edit:</p>
  
  <p>Ok, i figured it just creates a file with the valid base64 string
  but it doesn't get decoded</p>
  
  <hr>
  
  <p>Ok now i got at least this far:</p>
  
  <pre><code>  Option Public
    Option Declare
  
    Sub Initialize
  
        Dim session As NotesSession
        Dim doc As NotesDocument
        Dim query_string As String
        Dim params As Variant
        Dim i As Integer
        Dim db As NotesDatabase
        Set session = New NotesSession
        Set doc = session.DocumentContext
        query_string = doc.QUERY_STRING(0)
  
    On Error GoTo errorrt
        params = Split (query_string,"&amp;")
  
        Print("&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;")
  
        Print params(1);
        Print("&lt;br&gt;")
        Print ({&lt;img src="data:image/png;base64,} &amp; params(2) &amp; {"&gt;&lt;/img&gt;})
        Set db = session.Currentdatabase
        Set doc = db.Getdocumentbyunid(params(1))
        If doc Is Nothing Then
            Print ("Ne")
        End If
        Print (doc.Getitemvalue("tatkun")(0))
        Print ("&lt;/body&gt;&lt;/html&gt;")
  
        Call AttachSignature(doc,params(2),"signature")
  
        Exit Sub
    errorrt:
        Print (Error &amp; " " &amp; erl)
        Exit Sub
    End Sub
  
  
    Function AttachSignature(doc As NotesDocument, data As Variant, filename As String) As Boolean
  
    AttachSignature = False
  
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim body As NotesMIMEEntity
    Dim header As NotesMIMEHeader
    Dim child As NotesMIMEEntity
    Dim stream As NotesStream
    Dim fileType As String
    Dim rt1 As NotesRichTextItem
    Dim rt2 As NotesRichTextItem
  
    On Error GoTo ErrorRoutine
  
    Set db = doc.Parentdatabase
    Set stream = session.CreateStream
  
    Call stream.Writetext(data) 'Write the Data to the Stream
  
  
    If doc.Getitemvalue("SignatureAttached")(0) = "1" Then
        Exit Function
    End If
  
    Set body = doc.CreateMIMEEntity("TempRT")     
  
    Set header = body.CreateHeader("Content-Type") 
    Call header.SetHeaderVal("multipart/mixed")
  
    Call body.CreateHeader("Content-Disposition"). _
    SetheaderValAndParams({attachment; filename="} &amp;filename &amp; {"})
  
  
    Set child = body.CreateChildEntity()
  
    fileType = "image/jpeg"
  
        Call child.SetcontentfromText(stream, fileType, 1727) 
        Call stream.Close() 
        Call body.Decodecontent()
  
    Call doc.save(False, False)
  
    Set rt1 = doc.GetFirstItem("signature")
    Set rt2 = doc.GetFirstItem("TempRT")
  
    Call rt1.AppendRTItem( rt2 )
    Call rt2.Remove()
  
    doc.SignatureAttached = "1"
  
    Call doc.save(False, False)
  
    AttachSignature = True
  
    Exit Function
  
    ErrorRoutine:
     If Not rt2 Is Nothing Then
        Call rt2.Remove()
     End If 
     Print (Error &amp; " " &amp; Erl)
     Exit Function
    End Function
  </code></pre>
  
  <p>Which adds a valid image To the RichText item =)</p>
  
  <p>But i don't get how i could make it an inline image.
  And the filename isn't correct too.</p>
  
  <p>Again Thanx for any help =)</p>