Search code examples
c#windows-phone-7imgur

Base64 from e.ChosenPhoto apparently corrupted


            //convert photo to baos
            var memoryStream = new System.IO.MemoryStream();
            e.ChosenPhoto.CopyTo(memoryStream);
            //string baos = memoryStream.ToString();
            byte[] result = memoryStream.ToArray();
            String base64 = System.Convert.ToBase64String(result);
            String post_data = "&image=" + base64;
            ...
            wc.UploadStringAsync(imgur_api,"POST",post_data);  

I am using this code to upload an image to the Imgur API v3 using WebClient. The image being selected is either one of the 7 photos provided by the Windows Phone 7.1 emulator, or the simulated camera images. When I try to load the images, they are a largely-grey corrupted mess. Am I generating the base64 properly and/or do I need to render a Bitmap of the picture first before creating the byte[] and base64?

Thanks in advance!


Solution

  • Use something like Uri.EscapeDataString to escape the data so that special URL characters are not interpreted.