0

In my application i need to be able to capture image in browser then send it back to the server where it gets processed. currently i have a widget that captures an image and returns a pictureUrl for png image.

I'm looking for a best possible way to send it back to server.

Ideally i want this image put back inside the class that I originally fetch from server, then serialize it back to JSON and send to server.

Lets say for instance I heve the following C# class:

myClassWithImage{
    Bitmap myBitmap = null;
    ///many other properties
}

i serialize it to json and send it to the user.

Then i want react to use the instance of this class, update it with the picture, serialize to json & send back updated version. On server I just want to recreate the class instance using Newtonsoft.JSON like:

myClassWithImage imgCl = data.SelectToken("myClassWImage").ToObject<myClassWithImage>();

Is this possible at all? Or should i serialize images to base64 string ans send separately?

UPDATE:

I guess what I'm trying to find out if it is possible to serialize/deserialize the object directly into the instance of class without using additional Base64 string properties to it. If i try to add image Url directly to the myBitmap property I get

Newtonsoft.Json.JsonSerializationException: Newtonsoft.Json.JsonSerializationException: 'Error converting value "data:image/png;base64,....

So should i instead introduce another property to this class to hold the value of the image as string during serialization/deserialization?

AnKing
  • 1,994
  • 6
  • 31
  • 54
  • Yes it is possible, is it not working? Or what errors are you encountering? Personally, I'd use a property that's marked as serializable. Like public bitmap myBitMap {get;set;} type of thing... – Trey Nov 19 '18 at 15:58
  • If i put Base64 value directly into the myBitmap property I get Newtonsoft.Json.JsonSerializationException: 'Error converting value – AnKing Nov 19 '18 at 16:02
  • Sorry, I'm getting called into a meeting, try this: https://stackoverflow.com/questions/15510742/newtonsoft-json-deserializing-base64-image-fails – Trey Nov 19 '18 at 16:06

0 Answers0