0

I am trying to upload a picture to BaasBox in C#/Xamarin. So far I only get Bad Request errors:

WebRequest request = WebRequest.Create("http://localhost:9000/file");
            request.ContentType = "Content-type: image/jpg";
            request.Method = "POST";
            string authInfo = "user:password";
            request.Headers["Authorization"] = "Basic " + authInfo;

            byte[] buffer = new byte[16 * 1024];
            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = pictureFileStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                var bytearray = ms.ToArray();

                Stream reqstr = await request.GetRequestStreamAsync();
                reqstr.Write(bytearray, 0, buffer.Length);

                WebResponse response = await request.GetResponseAsync();
                Debug.WriteLine("Response: " + response);
            }

The documentation only says it is uploaded via post using parameter file?!

Thommy
  • 4,644
  • 2
  • 23
  • 43

0 Answers0