Classic ASP Base64, image/png -> save as image
<p>This particular question has been asked and answered, but no matter what I try I cannot get this to work. At this point I'm somewhat ready to toss my computer out the window..</p>

<p>No matter what combinations i try, it still fails at:</p>

<pre><code>oStream.write imagebinarydata   
</code></pre>

<p>Here is the code with comments:</p>

<pre><code>sFileName = Server.MapPath("grafer/test.png")
ByteArray = Request.Form("imageData")
ByteArray = [DATA-URI String] 'This string shows the image perfectly fine, in an image tag in the top of the page so it should be perfectly ok?

response.write ("Decoded: " &amp; Base64Decode(ByteArray)) '&lt;- Writes 'PNG' ?


Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2

Set oStream = Server.CreateObject("ADODB.Stream")

oStream.type = adTypeBinary
oStream.open 
imagebinarydata = Base64Decode(ByteArray) 
oStream.write imagebinarydata                                   '&lt;- FAILS

'Error: 

'ADODB.Stream error '800a0bb9'

'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

'Use this form to overwrite a file if it already exists
oStream.savetofile sFileName, adSaveCreateOverWrite

oStream.close

set oStream = nothing

response.write("success")

Function Base64Decode(ByVal vCode)

    Dim oXML, oNode

    Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
    Set oNode = oXML.CreateElement("base64")
    oNode.dataType = "bin.base64"
    oNode.text = vCode
    Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue)
    Set oNode = Nothing
    Set oXML = Nothing

End Function

Function Stream_BinaryToString(Binary)

    Const adTypeText = 2
    Const adTypeBinary = 1

    'Create Stream object
    Dim BinaryStream 'As New Stream
    Set BinaryStream = CreateObject("ADODB.Stream")

    'Specify stream type - we want To save text/string data.
    BinaryStream.Type = adTypeBinary

    'Open the stream And write text/string data To the object
    BinaryStream.Open

    BinaryStream.Write Binary 

    'Change stream type To binary
    BinaryStream.Position = 0
    BinaryStream.Type = adTypeText

    'Specify charset For the source text (unicode) data.
    If Len(CharSet) &gt; 0 Then
    BinaryStream.CharSet = CharSet
    Else
    BinaryStream.CharSet = "us-ascii"
    End If

    'Open the stream And get binary data from the object
    Stream_BinaryToString = BinaryStream.ReadText

End Function
</code></pre>