web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Convert embedded Infop...
Power Automate
Unanswered

Convert embedded Infopath image to html image

(0) ShareShare
ReportReport
Posted on by 9

Greetings!

 

I have an old Infopath system stored in SharePoint. Now I'm trying to use Power Automate to extract embedded images from there. I found how to get text part which represents image inside. So for example "x0lGQRAAA...." here is image header and image content, as I understand:

 

text-2023-03-31_020514.png

 

But here I stucked. I know how to create html file but cannot convert infopath encoded string to html:

 

<img src="data&colon;image/png;base64,x0lGQRQAAAABAAAAAAAAAPmaAAAkAAAAIQQ9BDgEPAQ..." />
 

Tried to use this string like this, but this does not work:

compose-2023-03-31_020932.png

As I understand there is encoded header in this string, this is not clear file content.

Also tried to use base64ToBinary conversion and then extract content like described here

 

outputs('Compose_base64ToBinary')?['body/$content']

 

binary-2023-03-31_022813.png

 

But it also does not work, base64ToBinary has same string in 'content':

to-binary-2023-03-31_022341.png

How to convert this infopath string to something I can work. Or how to decode header and image content  (some images could have *.png type, and other *.jpg, etc.)

Categories:
  • Rockie Profile Picture
    9 on at

    Update:

     

    So Infopath XML stores embedded images in base64 string, which contains file name/type and file content. Here are two embedded images:

     

    form-image-2023-03-31_185822.png

     

     

     

     

     

     

     

     

     

     

    In Infopath XML this image is stored like base64 string:

     

    <my:group4>
     <my:field18>
     <!-- jpg-image.jpg encoded in infopath form: -->
     x0lGQRQAAAABAAAAAAAAAO+aAAAOAAAAcABuAGcALQBpAG0AYQBnAGUALgB...
     </my:field18>
    </my:group4>

     

    First part contains file name and the second is encoded image.

     

    We can use encoded image part in html as image content like this: 

     

    <img src="data%3Aimage/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAA..." />

     

    But xml string in Infopath stores both filename and content in one line, so I need to read some bytes and split file name and image content

     

    Here I put examples of InfoPath string and C# code, that decodes it and get file name/and content strings:

    https://gist.github.com/Gennady-G/48d740c92593e1ce8234b4a8c3a23069

     

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Xml;
    using System.Xml.XPath;
    using System.Security.Cryptography;
    using System.IO;
    
    
    namespace getFilenameFromBase64
    {
     class Program
     {
    
     // "jpg-image.jpg" file encoded in infopath xml
     private static string base64FromInfopath = "x0lGQRQAAAABAAAAAAAAAPBgAAAOAAAAa....";
    
     // "png-image.png"
     //private static string base64FromInfopath = "x0lGQRQAAAABAAAAAAAAAO+aAAAOAAAAc...";
    
     static void Main(string[] args)
     {
     // This function from Quazi Anis gets filename from encoded string
     // https://www.infopathdev.com/forums/p/15120/53720.aspx#53720
     Encoding _encoding = Encoding.Unicode;
    
     // Read base64 string and get header, filename and image content separately
     using (MemoryStream _memoryStream = new MemoryStream(Convert.FromBase64String(Program.base64FromInfopath)))
     {
     BinaryReader _theReader = new BinaryReader(_memoryStream);
     byte[] _headerData = _theReader.ReadBytes(16);
     int _fileSize = (int)_theReader.ReadUInt32();
    
     int _imageNameLength = (int)_theReader.ReadUInt32() * 2;
     byte[] _fileNameBytes = _theReader.ReadBytes(_imageNameLength);
    
     // here is file name decoded:
     string fileName = _encoding.GetString(_fileNameBytes, 0, _imageNameLength - 2);
     Console.WriteLine(fileName); // result: "jpg-image.jpg"
    
     // and here is base64 data of pure image that we can use in html: <img src="data&colon;image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqMAAAIZCAIAAAAdrK.." />
     var imageContentInBytes = _theReader.ReadBytes(_fileSize);
     var imageContentAsString = Convert.ToBase64String(imageContentInBytes); // result: "iVBORw0KGgoAAAANSUhEUgAAAqMAAAIZCAIAAAAdrK.."
    
     Console.WriteLine(imageContentAsString);
     }
     }
     }
    }

     

     

    Here are project sources if needed:

    https://github.com/Gennady-G/ExtractImageFromInfopathXml/blob/main/getFilenameFromBase64/getFilenameFromBase64/Program.cs

     

    Can I do something similar (make operations with bytes array) in SharePoint power automate? Or what You think I can do to decode base64 string and extract file name/type and image content from there?

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 355

#2
11manish Profile Picture

11manish 336 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 308

Last 30 days Overall leaderboard