Power Automate file contents base64

Posted by John Liu on Tuesday, March 29, 2022

When using Power Automate flow to upload a CSV file to SQL server, the base64 value in the flow will be converted to a UTF-8 binary value if the target column data type is varbinary, or the raw base64 string value if the column data type is varchar/nvarchar.

However, when the original data contains unicode string value like Chinese character, the varbinary data type will not be able to be converted back to its original unicode text. Using the varchar/nvarchar data type to store the original base64 string value and then using following conversion to convert back to the original unicode text.

SELECT CONVERT(NVARCHAR(MAX),
                CONVERT(XML,
                        '<?xml version="1.0" encoding="UTF-8"?>' +
                        CONVERT(VARCHAR(MAX),
                                CONVERT(XML, [Base64String])
                                  .value('.','varbinary(max)')
                               )
                       )
               )