Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/70611?pagenum=1
04 November 2025, 18:35
Topic
Shaggy
Convert PNG to Base64 in ASP
10 October 2013, 08:05
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:
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.
Replies ...
Carefree
10 October 2013, 10:17
You might try replacing your response.write with something like this:
Code:
If instr(objXml.text,"Content-Type: image/png") AND lCase(right(filename,4))=".png" then response.Write replace(instr(objXml.text,"Content-Type: image/png")+24) End If
That SHOULD just start from the position after that line (23 characters of text plus a line feed/carriage return).
Shaggy
10 October 2013, 10:37
Thanks, Carefree, but objXml.text is Base64 encoded binary data so that's not going to work.
Carefree
10 October 2013, 11:04
So objStream is your initial file? OK.
Code:
If instr(objStream,"Content-Type: image/png") AND lCase(right(filename,4))=".png" then response.Write replace(instr(objXml.text,"Content-Type: image/png")+24) End If
Shaggy
10 October 2013, 11:10
No, the initial data comes from binFile=request.binaryread(request.totalbytes) and I need to strip out the header data before binFile gets passed to the stream so that all that's going into the stream is the file data.
Carefree
15 October 2013, 15:47
Originally posted by Shaggy No, the initial data comes from binFile=request.binaryread(request.totalbytes) and I need to strip out the header data before binFile gets passed to the stream so that all that's going into the stream is the file data.
Code:
If instr(binfile,"Content-Type: image/png") AND lCase(right(filename,4))=".png" then For i = 1 to len(binfile) If mid(binfile,i,23)="Content-Type: image/png" Then binfile=mid(binfile,i+24,len(binfile)-i+24) Exit For End If Next End If