Getting Base64 string from ImageAttachment Control in K2

341 views Asked by At

I am trying to upload an image in sql server using K2 ImageAttachment when I am doing InputMapping the image gets stored as an xml having file path. I want to store it as base64 string of image not xml path but the actual image base64 string. Any clue?

<collection><object><fields><field name='FileName'><value>Capture.PNG</value></field><field name='FilePath'><value>AB177CDDBA29104CD0E1AE3F14DCDD4B\Capture.PNG</value></field><field name='FileRequestData'><value></value></field><field name='FileDataURL'><value></value></field></fields></object></collection>
1

There are 1 answers

0
Shane On

I did this via C#;

    // BMP, GIF, JPEG, PNG, TIFF
using (System.Drawing.Image img = System.Drawing.Image.FromFile(imgPath))
{
    using (MemoryStream ms = new MemoryStream())
    {
        img.Save(ms, img.RawFormat);
        imgNode.Attributes["src"].Value = "data:image/" + imgName.Substring(imgName.LastIndexOf('.') + 1) + @";base64," + Convert.ToBase64String(ms.ToArray());
    }
}