'www.youtube.com/teachComputing
'Import : System.IO, System.Net, System.Web, System.Text
'Ensure you add reference : system.web (.NET TAB)
'Also ensure your target framework is set to .NET 4.0 not Client profile!
#Region "Imgur Upload"
Private Sub PostToImgur()
Dim apiKey As String = "b9b03e223918469b258194599f5ef68b"
Dim imageData() As Byte
Dim fileStream As FileStream = File.OpenRead(path)
imageData = New Byte((fileStream.Length) - 1) {}
fileStream.Read(imageData, 0, imageData.Length)
fileStream.Close()
Dim uploadRequestString As String = HttpUtility.UrlEncode("image", Encoding.UTF8) + "=" + HttpUtility.UrlEncode(System.Convert.ToBase64String(imageData)) + "&" + HttpUtility.UrlEncode("key", Encoding.UTF8) + "=" + HttpUtility.UrlEncode(apiKey, Encoding.UTF8)
Dim webRequest As HttpWebRequest = CType(Net.WebRequest.Create("http://api.imgur.com/2/upload"), HttpWebRequest)
webRequest.Method = "POST"
webRequest.ContentType = "application/x-www-form-urlencoded"
webRequest.ServicePoint.Expect100Continue = False
Dim streamWriter As IO.StreamWriter = New IO.StreamWriter(webRequest.GetRequestStream)
streamWriter.Write(uploadRequestString)
streamWriter.Close()
Dim response As WebResponse = webRequest.GetResponse
Dim responseStream As Stream = response.GetResponseStream
Dim responseReader As StreamReader = New StreamReader(responseStream)
Dim responseString As String = responseReader.ReadToEnd
Dim ImageURL As String = Split(responseString, "<original>")(1).Split("<")(0)
TextBox1.Text = ImageURL
End Sub
#End Region