Forum Discussion
Binary to Image Conversion - BLOB Field from Dynamics NAV
I have tried all possibilities to convert a BLOB field (Bitmap) from a SQL DB (Dynamcis NAV 2013) table to an Image URL, but not been able to find a solution yet.
I converted the Binary file to Text then added a column as follows:
Then, changed the Data Category to Image URL, but the images are not showing up
Attempts that failed:
1. Tried the function: Binary.ToText([Picture],BinaryEncoding.Base64)
2. Removed image file extension and tried "data:image/<image_format>;base64," and "data:image/;base64,"
Appreciate any help on this
Thanks
5 Replies
- lbendlinSuper User
You followed these instructions?
https://blog.crossjoin.co.uk/2019/05/19/storing-large-images-in-power-bi-datasets/
- jmsceskiNew Member
NAV uses the first 4 bytes as a "magic number" that specifies the custom NAV Blob Type.
{2, 69, 125, 91}If you are storing an image in the NAV database, you need to prepend the four bytes to the base-64 encoded byte array containing the image. If you don't, and launch a page that references the Blob fields, NAV will crash.
If you are retrieving an image, you need to strip them. Otherwise, nothing except NAV is aware they are valid images.
Sample procedure I used to store an image in the database, you'll need to reverse it.
private static byte[] BlobMagic = new byte[] { 2, 69, 125, 91 }; private static byte[] CompressByteArray(byte[] data) { byte[] retVal; using (MemoryStream compressedMemoryStream = new MemoryStream()) { using (DeflateStream compressStream = new DeflateStream(compressedMemoryStream, CompressionMode.Compress, true)) { compressStream.Write(data, 0, data.Length); compressStream.Close(); retVal = new byte[compressedMemoryStream.Length]; compressedMemoryStream.Position = 0L; compressedMemoryStream.Read(retVal, 0, retVal.Length); compressedMemoryStream.Close(); compressStream.Close(); } } // add Blob Magic so NAV doesn't detect a human scent return BlobMagic.Concat(retVal).ToArray(); }