base64 image decoder for ASP classic

老子叫甜甜 提交于 2019-12-02 11:48:31

You can use the Capicom COM object. I've been using it to to the reverse (base64 encoding). This is what I would do (if you've got a big loop, you'd better have the CreateObject done outside the loop, but in simple cases this should do it):

Function Base64Decode(encodedString)
    Dim caputil : Set caputil = CreateObject("CAPICOM.Utilities")
    If len(encodedString) > 0 Then
        Base64Decode = caputil.Base64Decode(encodedString)
    Else
        Base64Decode = ""
    End If
    Set caputil = Nothing
End Property

Reference : http://msdn.microsoft.com/en-us/library/aa388176(v=vs.85).aspx

By the way, capicom.dll can be downloaded from MS site : http://www.microsoft.com/downloads/en/details.aspx?FamilyID=860ee43a-a843-462f-abb5-ff88ea5896f6

<%
Set objXML = Server.CreateObject("MSXml2.DOMDocument")
Set objDocElem = objXML.createElement("Base64Data")
objDocElem.DataType = "bin.base64"
objDocElem.text = "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAUD"  'encodedString

'Save to disk
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.Write objDocElem.NodeTypedValue
objStream.SaveToFile "abc.jpg", 2
set objStream = Nothing


'Or send to browser
Response.ContentType = "image/jpeg"
Response.AddHeader "Content-Disposition", "attachment; filename=abc.jpg";
Response.BinaryWrite objDocElem.NodeTypedValue

Set objXML = Nothing
Set objDocElem = Nothing
%>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!