0

我正在尝试编写一个通过 xmlhttprequest 运行并接受 UNID 和 Base64 编码图像作为参数的代理。

我要做的是代理解码 base64 字符串并将其作为内联图像写入 RichText 字段

我尝试将 base64 编码字符串写入 Stream,然后使用子实体创建 MimeEntity 并设置流中的内容,然后获取 MimeEntity Item 并将其附加到 RichTextItem

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

但我最终得到了一个 6400 字节的图像/jpeg 文件现在我没有得到任何进一步

有没有人知道如何让这样的东西工作?提前致谢 =)

编辑:

好的,我认为它只是使用有效的 base64 字符串创建了一个文件,但它没有被解码


好的,现在我至少做到了这一点:

  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,"&")

      Print("<html><head></head><body>")

      Print params(1);
      Print("<br>")
      Print ({<img src="data:image/png;base64,} & params(2) & {"></img>})
      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 ("</body></html>")

      Call AttachSignature(doc,params(2),"signature")

      Exit Sub
  errorrt:
      Print (Error & " " & 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="} &filename & {"})


  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 & " " & Erl)
   Exit Function
  End Function

它将有效图像添加到 RichText 项 =)

但我不明白如何使它成为内联图像。而且文件名也不正确。

再次感谢任何帮助 =)

4

2 回答 2

0

我相信您希望使用 multipart/related 而不是 multipart/mixed,并将 Content-ID: 标头分配给存储 iamge 的 MIMEEntity,然后用于引用图像中的内容 ID。

于 2012-10-11T18:52:51.837 回答
0

希望这可以解决。

Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim doc As NotesDocument
    'Dim acl As NotesACL
    'Dim entry As NotesACLEntry
    Dim richStyle As NotesRichTextStyle
    Dim rtitem As NotesRichTextItem
    Set db = session.CurrentDatabase
    Set doc = db.CreateDocument
    Dim s As New NotesSession
    Dim stream As NotesStream   
    Dim body As NotesMIMEEntity
    Dim child As NotesMimeEntity
    Dim header As NotesMIMEHeader
    Set body =  doc.CreateMIMEEntity("RT")


    topString = Split(BASE64, ",")

    Dim tmp_array() As String
    i = 0

    For i = 0 To Ubound(topString)
        Redim Preserve tmp_array(i)
        tmp_array(i) = topString(i)

        Set child = body.CreateChildEntity()
        Set header = child.CreateHeader("Content-Type")
        Call header.SetHeaderVal("multipart/mixed") 
        Set header =child.createHeader("Content-Disposition")
        Call header.setHeaderVal({attachment; filename=test} &Cstr(i)& {.jpg}) 'file name and type should be config


        Set header =child.CreateHeader("Content-ID")
        Call header.SetHeaderVal("test" &Cstr(i)& ".jpg")

        Set stream = s.CreateStream()
        Call stream.WriteText(topString(i))
        Call child.SetContentFromText(stream, "", ENC_BASE64)




    Next

    doc.form="Attachment"
    'doc.Attachment = tmp_array 
    Call doc.save(True,False)
    Call stream.Close() 
    s.ConvertMIME = True ' Restore conversion
于 2016-08-02T03:15:10.947 回答