I have a problem with the API upload and was not able to fix it in many hours.
Maybe you can and want to help me.
So i try to upload an image which i encoded in a Base64 String and i always get the error Can't create image from source. (I use POST)
If i try to upload an image from a website then it works but not with the base64 String of local files.
This is a base64 String i use for example:
I am doing this with Visual Basic (something like C#).
Maybe u already know what i do wrong or you have an idea what i have to observe, if not you maybe understand a little bit of the vb.NET Code i'm using to do this:
It is ok if you can't help me, maybe i am able to fix this in some more days of work 😉
Maybe you can and want to help me.
So i try to upload an image which i encoded in a Base64 String and i always get the error Can't create image from source. (I use POST)
If i try to upload an image from a website then it works but not with the base64 String of local files.
This is a base64 String i use for example:
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAzAGMDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUl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h+yurB5dR1bV74wyLINy2sgVy0SxPJGBt8vZt3qScscngvvPE/iyKLSrBdFEesXSTyyL5cUg2RsqghDcooLBwxAlYr0+bOR1txomk3cd1Hc6XZTJdsrXKy26MJiuNpcEfMRgYz0xUUvhvQp9Nh02bRdOksIW3RWr2qGJDzyqYwDyeg7mgRzGo+JvE1vFdy+RpdgbDSItQuoboNKfMJl3RBlcKB+7+9zj0bPFa/wDFZPiqG6Q6pHb2UsFvNEltObc+Yv70u6r5YKb4j8xBGxvXnpW8H6PLr66pcafYzCG2ht7SKS0Q/ZvLZ2BQn7v3xwAMbR+Gs2nWL2s9q9nbtb3BYzRGJSkhb724Ywc989afW/8AX9WB9l/Wi/Uy7zwf4ZvruW6u/DmkXFxK26SWWxjd3PqSVyTRTrjwb4WvLiS4ufDWjzzyNueWWxiZmPqSVyTRXO6Tb3Hc26KKK3EFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAf/w==
I am doing this with Visual Basic (something like C#).
Maybe u already know what i do wrong or you have an idea what i have to observe, if not you maybe understand a little bit of the vb.NET Code i'm using to do this:
Code:
Dim Request As HttpWebRequest = CType(WebRequest.Create("http://mywebsite.net/api/1/upload/?key=myAPIKey&format=redirect"), HttpWebRequest)
Request.Method = "POST"
Request.ContentType = "application/x-www-form-urlencoded"
Request.AllowAutoRedirect = True
Dim Post As String = ""
//Get the Bytes of the Image
Dim memory As New System.IO.MemoryStream()
m_image.Clone.Save(memory, Imaging.ImageFormat.Jpeg)
Dim imageBytes() As Byte = memory.ToArray()
memory.Close()
//Convert the Bytes to base64
Dim base64String As String = Convert.ToBase64String(imageBytes, 0, imageBytes.GetUpperBound(0))
Post = "&source=" & base64String
// If i do this it works: Post = "&source=http://somewebsite.com/image.jpg"
Dim byteArray() As Byte = Encoding.UTF8.GetBytes(Post)
Request.ContentLength = byteArray.Length
Dim DataStream As IO.Stream = Request.GetRequestStream()
DataStream.Write(byteArray, 0, byteArray.Length)
DataStream.Close()
Dim Response As HttpWebResponse = Request.GetResponse()
DataStream = Response.GetResponseStream()
Dim reader As New IO.StreamReader(DataStream)
Dim ServerResponse As String = reader.ReadToEnd()
reader.Close()
DataStream.Close()
Response.Close()
MessageBox.Show(ServerResponse)
It is ok if you can't help me, maybe i am able to fix this in some more days of work 😉