views:

41

answers:

2

I have an asp.net MVC application that takes in uploaded NMEA track files from small GPS loggers. In some cases, the loggers will inject null (0x0) values into the track file text. Is there a way to strip out these 0x0 characters from the HttpPostedFile's InputStream before saving the file to the server's file system for processing? As it is, I can only get to the first null character and that's all of the file that gets saved on the server.

Thanks, Matthew

A: 

InputStream is binary and shouldn't care about zeros. So, the problem is with the data conversion to text - but you didn't show the code that you use to convert.

You may manually skip/replaces zeros:

var outstream = new StringStream();
var b;
while ((b = http.InputStream.ReadByte()) != -1)
  if (b != 0)
      outstream.Write(b);

and now you got stream without zeros (of course you can read in blocks, etc, if you want to).

queen3
I'm not doing any conversion now; simply calling the .SaveAs(path) method of the HttpPostedFile that's uploaded.
Matthew Belk
A: 

If you use SaveAs, it should write zeros. Can you check the InputStream content in debugger (for example using my reading method above) - are you sure that HttpPostedFile does contain zeros - that is, that you receive data correctly? Do you use ENCTYPE="multipart/form-data" for your upload form?

queen3