0

I have c# client and c# server (mvc4 api controller) and I want to transfer image via json. I write on the client:

var memoryStream = new MemoryStream();
image.Save(memoryStream, ImageFormat.Jpeg);
var baseStr64 = Convert.ToBase64String(memoryStream.ToArray());
response.Image = baseStr64;
(new JavaScriptSerializer).Serialize(response);
...Sending

Without image controller gets the request class normal, but with image base64 string field I have a null parameter in controller. Then I noticed that output json fails in online json validators on this base64 field. My output json can be found here: http://pastebin.com/wnAJpZGV

How to transmit image correctly?

Igor Koks
  • 33
  • 5
  • Can I know the reason why you are sending Image in JSON, and shy are you not sending it in Request Body? Is there any specific reason? You can send both formdata and filedata in multipartform to Web API, check this tutorial - http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2 – ramiramilu Feb 09 '14 at 08:34

1 Answers1

0

It is possible that the Json string is too big. The PasteBin example you showed was over 200K in length. Check this StackOverflow article on how you might be able to fix the problem:

Can I set an unlimited length for maxJsonLength in web.config?

Community
  • 1
  • 1
jwatts1980
  • 7,254
  • 2
  • 28
  • 44