-
-
Save catwhocode/058a25c308caeb436bcdf8bde905ae5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' http://web.archive.org/web/20060527094535/http://www.nonhostile.com/howto-encode-decode-base64-vb6.asp | |
' http://cwestblog.com/2013/09/23/vbscript-convert-image-to-base-64/ | |
Public Function ConvertFileToBase64(strFilePath As String) As String | |
Const UseBinaryStreamType = 1 | |
Dim streamInput: Set streamInput = CreateObject("ADODB.Stream") | |
Dim xmlDoc: Set xmlDoc = CreateObject("Microsoft.XMLDOM") | |
Dim xmlElem: Set xmlElem = xmlDoc.createElement("tmp") | |
streamInput.Open | |
streamInput.Type = UseBinaryStreamType | |
streamInput.LoadFromFile strFilePath | |
xmlElem.dataType = "bin.base64" | |
xmlElem.nodeTypedValue = streamInput.Read | |
ConvertFileToBase64 = Replace(xmlElem.Text, vbLf, "") | |
Set streamInput = Nothing | |
Set xmlDoc = Nothing | |
Set xmlElem = Nothing | |
End Function | |
Public Sub ConvertBase64ToFile(strFilePath As String, strBase64 As String) | |
Const UseBinaryStreamType = 1 | |
Const SaveWillCreateOrOverwrite = 2 | |
Dim streamOutput: Set streamOutput = CreateObject("ADODB.Stream") | |
Dim xmlDoc: Set xmlDoc = CreateObject("Microsoft.XMLDOM") | |
Dim xmlElem: Set xmlElem = xmlDoc.createElement("tmp") | |
xmlElem.dataType = "bin.base64" | |
xmlElem.Text = strBase64 | |
streamOutput.Open | |
streamOutput.Type = UseBinaryStreamType | |
streamOutput.Write = xmlElem.nodeTypedValue | |
streamOutput.SaveToFile strFilePath, SaveWillCreateOrOverwrite | |
Set streamOutput = Nothing | |
Set xmlDoc = Nothing | |
Set xmlElem = Nothing | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment