I am trying to send an image to an Imgur server. Everything went well and I get the URL of the image from the parser, but when I try to open it in a web browser, I don't get the image ... only the βbroken imageβ icon.
I think this is a problem in converting to an array of bytes .... but I do not understand this. let me know / correct my code.
Dim image As Image = image.FromFile(OpenFile.FileName)
Dim ms As New MemoryStream()
' Convert Image to byte[]
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim imageBytes As Byte() = ms.ToArray()
Dim wb As WebRequest = WebRequest.Create(New Uri("http://imgur.com/api/upload.xml"))
wb.ContentType = "application/x-www-form-urlencoded"
wb.Method = "POST"
wb.Timeout = 10000
Console.WriteLine(imageBytes.Length)
Dim parameters As String = "key=a801fa0b08a2117f5bb62b006f769b99&image=" + Convert.ToBase64String(imageBytes)
Dim encoding As New System.Text.UTF8Encoding()
Dim bytes As Byte() = encoding.GetBytes(parameters)
Dim os As System.IO.Stream = Nothing
Try
wb.ContentLength = bytes.Length
os = wb.GetRequestStream()
os.Write(bytes, 0, bytes.Length)
Dim xmlData As String = POSThandling.makePOSTrequest("http://imgur.com/api/upload.xml", New String() {parameters})
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.LoadXml(xmlData)
Dim name As XmlNodeList = xmlDoc.GetElementsByTagName("original_image")
Dim imageText As String = (name(0).InnerText).ToString
messageText.Text = imageText.ToString
PanelUpload.Visible = False
UpImage.Enabled = True
SendMsg.Enabled = True
Finally
If Not (os Is Nothing) Then
End If
End Try
source
share