0

I'm developing Windows phone(8.0)apps and I'm new to it,I'm using below code to post image to server in Base64 format using post client

Uri uri = new Uri(UPLOAD_IMAGE_PATH);
UploadImageData requestData = new UploadImageData();
requestData.image = base64String;
string jsonString = JsonConvert.SerializeObject(requestData);
PostClient proxy = new PostClient(jsonString);
proxy.DownloadStringCompleted += new PostClient.DownloadStringCompletedHandler(proxy_DownloadStringCompleted);
proxy.DownloadStringAsync(uri);

where base64String is my image string encoded in Bae64 by using below code

internal static string ImageToBase64String(Stream choosenPhoto,Image image)
{
   WriteableBitmap bmp = new WriteableBitmap((BitmapSource)image.Source);
   byte[] byteArray;
   using (MemoryStream stream = new MemoryStream())
   {
     bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
     byteArray = stream.ToArray();
     return Convert.ToBase64String(byteArray); 
   }           
}

In below response it returns "disallowed key charaters" on result.

void proxy_DownloadStringCompleted(object sender, WindowsPhonePostClient.DownloadStringCompletedEventArgs e)
{
   string result = e.Result;
}

But when i post same JSON string using REST Client from Mozilla, JSON response from server is successfull. I searched about this and i got some links link 1, link 2 that i need to allow characters on server side in Input.php file, So exactly what kind of character i need to allow. It works from REST Client did i miss something in my C# code, Please help me

Community
  • 1
  • 1
Raj Kumar
  • 736
  • 1
  • 12
  • 31
  • You really really shouldn't post a image as a base64 encoded string in a json request. Instead use a POST request with the binary data, and the .NET API will handle the conversion itself. – Claus Jørgensen Nov 08 '12 at 21:33
  • Thanks Claus, but API's are developed in PHP and i do not have any control on that. – Raj Kumar Nov 10 '12 at 12:05

1 Answers1

0

It doesn't seem to explicitly mention the Base64 string (unless I'm missing something, having never developed for a WinPhone OS). Have you checked the URL that you're sending a POST request to?

LMS
  • 4,117
  • 5
  • 27
  • 37