12 Years of Service
68%
[HIDE-THANKS][LENGUAJE=vb.net]Imports System.Net
Imports System.Text
Imports System.IO
dim ClientId as string = "Put your client id here"
Public Function UploadImage(ByVal image As String)
Dim w As New WebClient()
w.Headers.Add("Authorization", "Client-ID " & ClientId)
Dim Keys As New System.Collections.Specialized.NameValueCollection
Try
Keys.Add("image", Convert.ToBase64String(File.ReadAllBytes(image)))
Dim responseArray As Byte() = w.UploadValues("https://api.imgur.com/3/image", Keys)
Dim result = Encoding.ASCII.GetString(responseArray)
Dim reg As New System.Text.RegularExpressions.Regex("link"":""(.*?)""")
Dim match As Match = reg.Match(result)
Dim url As String = match.ToString.Replace("link"":""", "").Replace("""", "").Replace("\/", "/")
Return url
Catch s As Exception
MessageBox.Show("Something went wrong. " & s.Message)
Return "Failed!"
End Try
End Function
[/LENGUAJE]
[LENGUAJE=vb.net]
'Ejemplo de Uso:
'dim url as string = UploadImage(textbox1.text) 'path to the image
'messagebox.show(url)
[/LENGUAJE]
Fuente: pc-tips.net[/HIDE-THANKS]
Imports System.Text
Imports System.IO
dim ClientId as string = "Put your client id here"
Public Function UploadImage(ByVal image As String)
Dim w As New WebClient()
w.Headers.Add("Authorization", "Client-ID " & ClientId)
Dim Keys As New System.Collections.Specialized.NameValueCollection
Try
Keys.Add("image", Convert.ToBase64String(File.ReadAllBytes(image)))
Dim responseArray As Byte() = w.UploadValues("https://api.imgur.com/3/image", Keys)
Dim result = Encoding.ASCII.GetString(responseArray)
Dim reg As New System.Text.RegularExpressions.Regex("link"":""(.*?)""")
Dim match As Match = reg.Match(result)
Dim url As String = match.ToString.Replace("link"":""", "").Replace("""", "").Replace("\/", "/")
Return url
Catch s As Exception
MessageBox.Show("Something went wrong. " & s.Message)
Return "Failed!"
End Try
End Function
[/LENGUAJE]
[LENGUAJE=vb.net]
'Ejemplo de Uso:
'dim url as string = UploadImage(textbox1.text) 'path to the image
'messagebox.show(url)
[/LENGUAJE]
Fuente: pc-tips.net[/HIDE-THANKS]
Last edited by a moderator: