【问题标题】:Lotusscript save base64 encoded string to file (DLL)Lotusscript 将 base64 编码的字符串保存到文件 (DLL)
【发布时间】:2019-10-16 15:24:33
【问题描述】:

[编辑] 我相信我遗漏了我原来的问题。对我来说,问题似乎在于将解码的 MIMEEntity 的内容传递给流,我想将其写入文件。无论我如何尝试,我都无法让 Lotus 脚本将二进制数据写入文件。如果有人有任何有用的意见/建议/等等,我将不胜感激!

[原创] 我有以下代码

Dim a As String
a = "TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" & _
"AAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1v" & _
...
...

Dim session As New NotesSession
Dim stream As NotesStream
Dim doc As NotesDocument
Dim body As NotesMimeEntity
Dim db As NotesDatabase
Set session = New NotesSession

 'Create stream and display properties
Set stream = session.CreateStream

 'check if the file exists
If Not stream.Open("C:\\Notes\\update.dll") Then
     'if the file doesnot exist then create one and add a time stamp to it
    Dim fileNum As Integer
    fileNum% = Freefile()
    Open "/ww414/notes/ebcdicfile.txt" For Output As fileNum%
    Close fileNum%
     'this should have created the file. see if it existis now
    If Not stream.Open("C:\\Notes\\update.dll") Then
   'if the file has not been created yet then let the user know of the error that blocks the operation
        Messagebox("Log file Is inaccessible")
    End If
End If

Dim b As NotesStream
Set b = session.CreateStream

Call b.WriteText(a)
'==========================================================


'update file with the b64 decoded content
Set db = session.CurrentDatabase
Set doc = db.CreateDocument
session.ConvertMime = False

Set body = doc.CreateMIMEEntity
Call body.SetContentFromText(b, "", ENC_BASE64)
Call body.DecodeContent
content = body.ContentAsText
Call stream.WriteText(content)

'close stream/file open in memory
Call stream.Close()

问题是,文件被创建了,但是当涉及到内容时,它只是在其中放入了几个字节(而不是 14kb 的实际文件数据)

我检查了一堆论坛和可能的解决方案,但似乎没有一个有效。 例如: https://www.nsftools.com/tips/Base64v14.lss

http://www-10.lotus.com/ldd/nd6forum.nsf/e5f5333619f2996885256a220009508f/a8bb2c21c99f9c4d852571ee005cede9?OpenDocument

https://ghads.wordpress.com/2008/10/17/vbscript-readwrite-binary-encodedecode-base64/

【问题讨论】:

  • 只是一个想法,如果您流式传输到具有不同扩展名的文件(例如 .jpg 或 .gif),它是否有效?假设是某些防病毒进程阻止您动态创建 .dll。
  • 嗨!不幸的是:(我遍历了所有可能的文件格式,还尝试设置 mime 标头(因此它会将其识别为“application/octet-stream”等)但没有成功。另外,我试图复制这个人的内容做了stackoverflow.com/questions/45796962/…,但同样没有成功。
  • 来自 ContentAsText 属性帮助“非文本数据按原样返回,这可能会在进一步处理时出现问题。例如,包含空字符的数据可能会在字符串操作期间在空字符处被截断”在我看来,你真的想要 .GetContentAsBytest() 方法。
  • 我也试过了,但由于某些原因它不起作用。但是,我终于让它工作了!一会儿我会在下面写一个详细的答案。非常感谢你们!

标签: vb.net lotus-notes lotus-domino lotusscript lotus


【解决方案1】:

所以,解决方案比我想象的更简单。

This 提供了巨大的帮助,因为我的问题的根本原因似乎是将二进制内容写入磁盘。那是由于以错误的方式创建文件!创建文件时,它无法正确输出内容(出于某些“Lotus 原因”..)

不管怎样,喝杯咖啡休息一下,从零开始一切都会有很大帮助!有效的代码(供将来参考。如果有人需要让这样的东西工作):

Sub Initialize

Dim a As String
a ="BASE64 ENCODED STRING(In my case it was a DLL)" 

Dim session As New NotesSession
Dim stream As NotesStream
Dim doc As NotesDocument
Dim body As NotesMimeEntity
Dim db As NotesDatabase
Set session = New NotesSession

Set stream = session.CreateStream

Dim b As NotesStream
Set b = session.CreateStream

Call b.WriteText(a, EOL_NONE)

Set db = session.CurrentDatabase
Set doc = db.CreateDocument
session.ConvertMime = False

Set mime = doc.CreateMIMEEntity
Call mime.SetContentFromText(b, "application/octet-stream", ENC_BASE64)
Call mime.DecodeContent

If Not(mime Is Nothing) Then
    Set stream = session.CreateStream
    pathname$ = "c:\temp\test.dll"
    If Not stream.Open(pathname$, "binary") Then
        Messagebox pathname$,, "Open failed"
        Goto ExitSub
    End If
    Call mime.GetContentAsBytes(stream)
    Call stream.Close
Else
    Messagebox "Not MIME",, doc.GetItemValue("Subject")(0)
End If  
ExitSub:
    session.ConvertMIME = True ' Restore conversion
End Sub

【讨论】:

  • 有效字符集包括:ASCII、Big5、Binary、EUC-JP、EUC-KR、EUC-TW、GB2312、ISO-2022-JP、ISO-2022-KR、ISO-8859-1通过 ISO-8859-9、ISO-8859-15、KOI8-R、Latin4、Shift_JIS、System、TCVN3、Unicode、Unicode-1-1、US-ASCII、UTF-7、UTF-8、UTF-16、UTF -16BE、UTF-16LE、Windows-1250 到 Windows-1258 和 Windows-874。二进制意味着仅对流进行字节操作。默认为“系统”,这显然意味着“文本”。他们所缺少的只是摩尔斯电码。很高兴你成功了。
猜你喜欢
  • 1970-01-01
  • 2016-12-03
  • 1970-01-01
  • 2021-03-13
  • 2011-09-10
  • 2016-01-11
  • 2013-06-04
  • 1970-01-01
  • 2021-01-23
相关资源
最近更新 更多