1

In Microsoft Dynamics Business Central, the images can be saved in the [Tenant Media] table. The field [Mime Type] tells the type, and the field Content stores the binary content (as varbinary type).

I need to mirror the images of the goods to another database using the C# code. However, it seems that the Content field does not store only the plain binary of the image.

Is the content encrypted somehow? When read to byte[], is it possible to get the image data?

pepr
  • 20,112
  • 15
  • 76
  • 139

1 Answers1

1

Here is a c# solution for NAV 2013 and above based on this solution https://devch.wordpress.com/2014/01/21/accessing-compressed-blobs-from-outside-nav-nav2013-revisited/

 byte[] dest = new byte[tenantMedia.Content.Length - 4];
 Array.Copy(tenantMedia.Content, 4, dest, 0, dest.Length);

 MemoryStream stream = new MemoryStream(dest);
 using (DeflateStream deflateStream = new DeflateStream(stream, CompressionMode.Decompress))
 {
      MemoryStream ResultStream = new MemoryStream();
      deflateStream.CopyTo(ResultStream);
      byte[] uncompressedContent = ResultStream.ToArray();

      string base64Image = Convert.ToBase64String(uncompressedContent);
      Console.WriteLine(base64Image);
  }

For version previous to NAV 2013:

http://midynav.blogspot.com/2009/04/blob-fields-with-nav-sql_28.html

[ Out of the box, NAV flags a "BLOB" field with the property "Compressed" = TRUE. If this is enabled, NAV uses a compression algorithm to save the data more compact. Have in mind that SQL Server does not recognize this "compression", so if you're using BLOB to transfer binary data from NAV to other SQL systems – which could be very smart, but that's a different story! – you should make sure to set "Compressed" to FALSE. But anyway … ]

See also: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-compressed-property

Timothy Martens
  • 678
  • 4
  • 17