I am using a modification of code posted by Moose located at https://stackoverflow.com/a/566477/5061596 to do a WebRequest to send a binary file to a device. I've modified it for vb.net as such:
Dim updateFile() As Byte = File.ReadAllBytes(myUpdateFile)
Dim request As HttpWebRequest = HttpWebRequest.Create(myUpdateFileURL)
request.Method = "POST"
request.Timeout = 300000 ' 5 minutes
request.ProtocolVersion = HttpVersion.Version10
request.Credentials = myCredentials
request.ContentLength = updateFile.Length
request.ContentType = "application/octet-stream"
Dim stream As Stream = request.GetRequestStream
stream.Write(updateFile, 0, updateFile.Length)
stream.Close()
This code is working fine but it seems httpWebRequest is in general "slow" and some of the devices I'm working with are 10Mb Ethernet connections. Those two items combined is giving me 2 - 2:30 minute uploads on 100Mb files. For this reason I would like to implement some type of feedback. Is there a easy way to modify this code for status? I would think so since I know the file length already. The problem is each time I try to modify it to loop through chunks of the file being uploaded I'm doing something wrong which is, for lack of better terms, destroying the file and the receiving device rejects it.