I have a handler that handles single files (text based) perfectly. I can receive .zip files but they are unable to be accessed due to “corruption” errors. I know that this is due to reading things in as a text stream and not a byte array but I cannot figure it out. (My attempt is below)
EDIT:
I need to be able to have the handler accept .zips without corruption errors. I got past the corruption errors but the below code handles the file without corruption issues but unzips it with no files inside.
Sub ProcessRequest(ByVal context as HttpContent) Implements IHTTPHandler.ProcessRequest
Try
If Context.Request.HttpMethod() = "POST" Then
context.Response.ContentType = "application/octet-stream"
context.Response.StatusCode = 204
Dim reader as New System.IO.BinaryReader(context.Request.InputStream)
Dim contents as Byte
Dim int as Integer = reader.Basestream.Length
''Problem has got to be here, This loop structure can't be right..
Do While int > 0
contents = reader.readByte()
System.IO.File.WriteAllText("thisismyoutputdirectory"), filename), contents)
Loop
else
''Handle non post cases
end if
Catch ex as Exception
''Error Handling is here
End Try
End Sub
Instead of Streamreader I am using BinaryReader. I have attempted to save contents as a byte array and then write them all out using the WriteAllBytes method.
I will continue experiementing but any guidance would be great!
I just solved the issue. I simply needed to write it out to a byte array and save an integer to represent the number of bytes. Then simply print the contents. It looks like I was trying to make things more complicated.
My loop in original code is kinda ugly 🙁