The Forum has been Updated
The code has been upgraded to the latest .NET core version. Please check instructions in the Community Announcements about migrating your account.
Greetings, strangers
Hoping one of you may be able to help me with this little script.
I'm trying to write an ASP script to convert PNG files submitted through a form to Base64 strings without writing the file to the server first.
The HTML for the form is straightforward, as follows:And the code to process it and convert it to Base64 is as follows:All works well, except the Base64 string includes the form "header" - Example:Any suggestions/pointers for stripping it out at any stage of the process before the encoding takes place? Ideally, I'd also like to read "filename" and "Content-Type" into variables to help me verify that the file is actually a PNG.
I'm trying to write an ASP script to convert PNG files submitted through a form to Base64 strings without writing the file to the server first.
The HTML for the form is straightforward, as follows:
Code:
<form enctype="multipart/form-data" method="post">
<input type="file" name="file" />
<button type="submit">Convert</button>
</form>Code:
dim objXml,objStream,binFile
binFile=request.binaryread(request.totalbytes)
set objStream=server.createobject("ADODB.Stream")
objStream.type=1
objStream.open
objStream.write binFile
set objXML=server.createobject("MSXml2.DOMDocument")
set objXml=objXml.createelement("Base64Data")
objXml.datatype="bin.base64"
objXml.nodetypedvalue=objStream.read
response.write replace objXml.text
objStream.close:set objStream=nothing:set objXml=nothingCode:
------WebKitFormBoundarydXk7Jv8nzVuN2zps
Content-Disposition: form-data; name="file"; filename="file.png"
Content-Type: image/png
[File data here]
