I have an Image saved as varbinary(max) in SQL Server 2014:
0xFFD8FFE115064578696600004D4D002A0000000800070...........
I want to convert it to Base64 To use it in Flutter. I tried
SELECT CAST('' as varbinary(max)) FOR XML PATH(''), BINARY BASE64
and get :
MHhGRkQ4RkZFMTE1MDY0NTc4Njk2NjAwMDA0RDREMDAyQTAwMDAwMDA4MDAwN..........
But according to this site I should get:
/9j/4RUGRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAA........
So how to convert varbinary(max) to base64?
Why are you attempting to
CAST()the varbinary data? You just need to select it as an element or an attribute for the varbinary value to get base64 encoded...The first select outputs the base data in an element:
The second select outputs the base64 data in an attribute:
Following comments discussion with @DaleK, a third alternative to return the bare base64 characters without any XML tags:
Which outputs: