直接从 Microsoft Dynamic Business Central 的 [Tenant Media] 表中读取图像?

huangapple go评论47阅读模式
英文:

Reading image directly from the [Tenant Media] table in Microsoft Dynamic Business Central?

问题

在Microsoft Dynamics Business Central中,图像可以保存在[Tenant Media]表中。字段[Mime Type]指示类型,字段Content存储二进制内容(作为varbinary类型)。

我需要使用C#代码将商品的图像镜像到另一个数据库。然而,似乎Content字段并不仅仅存储图像的纯二进制数据。

内容是否以某种方式加密?在读取为byte[]时,是否可以获取图像数据?

英文:

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?

答案1

得分: 1

以下是您提供的代码的中文翻译:

这是一个基于该解决方案的NAV 2013及以上版本的C#解决方案: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);
}

对于NAV 2013之前的版本,请参考以下链接:http://midynav.blogspot.com/2009/04/blob-fields-with-nav-sql_28.html

[在NAV中,默认情况下,将“BLOB”字段的属性“Compressed”设置为TRUE。如果启用了此选项,NAV将使用压缩算法以更紧凑的方式保存数据。请注意,SQL Server不识别此“压缩”,因此如果您要使用BLOB将二进制数据从NAV传输到其他SQL系统 - 这可能非常聪明,但这是另一回事! - 您应该确保将“Compressed”设置为FALSE。但无论如何...]
另请参考:https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-compressed-property

请注意,这是代码的翻译部分,不包括您提到的问题的回答。

英文:

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

huangapple
  • 本文由 发表于 2023年6月15日 16:57:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76480814.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定