Forum Discussion
Display images from SQL Server database DirectQuery model
- 6 years ago
I was able to solve it with a SQL Server query by casting the image to VARBINARY(MAX), and then casting it to XML, and changing the value to VARCHAR(MAX). After that, I concatenated it with 'data:image/jpeg;base64, ', and was able to change the Data Category to ImageUrl.
Here is the query:
SELECT CONCAT('data:image/jpeg;base64, ', CAST('' as XML).value('xs:base64Binary(sql:column("BinaryPicture"))', 'VARCHAR(MAX)')) AS Picture FROM ( SELECT CAST(lmePicture AS VARBINARY(MAX)) AS BinaryPicture FROM Employees ) AS A
Hi Lyssillic,
I'd like to suggest you check the below blog to know more about how to analyze binary format image files.
Since you are in direct query mode, I'd like to suggest you write a t-sql query to add a custom column to convert binary to base64 text and add the prefix so that power bi can recognized these strings as image.
Storing Images in a PowerBI/Analysis Services Data Models
Transact-SQL: Convert VARBINARY to Base64 String and vice versa
Regards,
Xiaoxin Sheng
Anonymous I need to add one more thing: the OP's solution gets rid of the error message in PQ, but in Power BI, the visual stays stuck in load-forever-mode and then after a long long time, fails with a can't-load-visual style error message. So the problem is only half solved at this point.
Any idea how load images from an on-prem SQL Server via DirectQuery?
And before anybody asks: I tried everything: with the 'data:image/jpeg;base64' concatenated at the very beginning of the byte stream, without it, with and without Image URL categorization, and so on. The visual still refuses to load the image even though now all code runs without error message. And like I said before, if I concat the base64 info inside Power Query instead of at the source, the M query fails miserably.