base64 image decoder for ASP classic

前端 未结 2 1681
-上瘾入骨i
-上瘾入骨i 2021-01-26 03:08

Can any one tell me how to decode a base64 encoded image in classic ASP? The image is encoded by Java org.apache base64 class. The Java uses RFC 2045 for base64 decoding.

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-26 03:36

    <%
    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
    %>
    

提交回复
热议问题