I need to convert uploaded binary files to base64 string format on the fly. I\'m using ASP, Vbscript. Using Midori\'s component for base64 conversion. For small size files (
Use MSXML to do the encoding for you. Here is function encapsulating the procedure:-
Function ToBase64(rabyt)
Dim xml: Set xml = CreateObject("MSXML2.DOMDocument.3.0")
xml.LoadXml " "
xml.documentElement.dataType = "bin.base64"
xml.documentElement.nodeTypedValue = rabyt
ToBase64 = xml.documentElement.Text
End Function
Note this will include linebreaks in the base64 encoding but most base64 decoders are tolerant of linebreaks. If not you could simpy use Replace(base64, vbLF, "")
to remove them, this will still be quicker than a pure VBScript solution.
Edit Example usage:-
Dim sBase64: sBase64 = ToBase64(Request.BinaryRead(Request.TotalBytes))