Hi,
I am creating a web server capable of processing Multi-Part posts from incoming clients.
With multi-part (file posts) most of the stream is text, but the portion between the boundries is sometimes binary, if the user is trying to upload a binary file.
The problem im having is that the functionality offered by C# strings is, from what I can tell, required to parse the header, standard post data, etc .. but strings are not holding up so well when I try to store the incoming binary data to them. I've tried just about every Decoding.GetString() combination known to man.
Primarily I use regex.split to find the boundries within the string so that I can determine which parts are binary and need binary processing... so I do not immediately see an alternative to converting the stream data out of it's natural byte[] array form (from BinaryReader.Read)... but it seems I lose characters when I convert it to a string using any method I've found so far.
Surely I am not the first person who has found a need to convert a byte array to a string for simple parsing?
Here is a quick example:
Content-Type: Multipart/FormData; boundry=----------7xxexamp
le
------------7xxexample
Boundry Specific Headers etc etc
Content-Type="JFIF/JPEG"
ÿÿÿ0ÿ Adobe.... binary data, directly from the JPEG
------------7xxexample--
The biggest problem, again, is that I have to find those boundries ("----------7xxexample") within the stream, so I figure I need to convert the byte[] to a string. But in doing so it destroys a lot of the binary JPEG data.
Any help is greatly appreciated,
-Luke
Start Free Trial