Currently I have the following function:
Private Function uploadFile(ByVal fileName As String)
Dim data() As Byte = IO.File.ReadAllBytes(fileName)
Dim base64String = System.Convert.ToBase64String(data)
Dim uploadURL As String = "http://192.168.0.7/upload.php"
Try
Using client As New Net.WebClient
Dim reqParm As New Specialized.NameValueCollection
reqParm.Add("body", base64String)
Dim responsebytes = client.UploadValues(uploadURL, "POST", reqParm)
Dim responsebody = (New Text.UTF8Encoding).GetString(responsebytes)
End Using
Catch ex As System.Net.WebException
MsgBox(ex.Message)
Finally
'
End Try
End Function
This will send the file contents in an http request as a base64 encoded string. I’d like to add a progressbar so the progress can be monitored. With Java I could implement this by incrementing a bytes sent counter as I add one byte at a time to the output stream for the request. Do I have that same option with VB.net, or maybe another option? Thanks for any thoughts
You can use
UploadValuesAsyncand listen to the event handlersUploadProgressChangedandUploadValuesCompleted.Sample code: