Problem writing Image data

Posts   
 
    
Posts: 5
Joined: 07-Aug-2006
# Posted on: 07-Aug-2006 11:25:11   

I have an image in a database that I extract and save to XML using WriteXml.

This gets passed as an XmlNode to a web service that then writes the XML value back to an image data type in a different database.

I have some code for displaying the image on a site that reads the second database.

If I write image data to the database directly the images are displayed fine, but if I go via WriteXml, I've been unable to successfully return the image.

I have tried all the different encodings, and tried using a StreamWriter and a BinaryReader (using ReadBytes) to extract the XML data value and write to the underlying entity, but to no avail.

If anyone has any ideas, I'd be very grateful.

Thanks,

CD

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 07-Aug-2006 11:54:25   

Here is what the writexml does with your image:

case "System.Byte[]": // special case, base64encode it byte[] valueToConvert = (byte[])propertyValue; valueAsString = Convert.ToBase64String( valueToConvert, 0, valueToConvert.Length ); break;

and what the read xml calls:

case "System.Byte[]": toReturn = Convert.FromBase64String(xmlValue); break;

But now you should keep in sync with your calls:

either you keep up with the entities (adapter save/fetch) either you work with the xml (writexml/readxml)

But you should not use writexml to store it in the other image column. Writexml deals with the whole entity, of a given type. You cannot put anything else behind than a readxml from the same entitytype.

Then you can pass things between the entities, but they can't pick up the information into each others serialized bit.

Posts: 5
Joined: 07-Aug-2006
# Posted on: 07-Aug-2006 12:33:32   

Jesse,

Unfortunately syncing the objects is simply not possible as the data objects themselves are very different. I use WriteXml just as a convenient way of getting the underlying data, I only ever take the Entity/Fields information, and append lots of other stuff.

No matter anyway, I was missing the whole Base64 encoding bit, about the only one I hadn't tried.

Extracting the text from the Xml and then converting back to a byte[] and writing to the image data type in the new database works a treat.

Thanks for your help and the swift reply!

CD