【问题标题】:How to get the file extension or content type from file byte array. in C# [duplicate]如何从文件字节数组中获取文件扩展名或内容类型。在 C# [重复]
【发布时间】:2017-01-08 04:19:24
【问题描述】:

如何从文件字节数组中获取文件扩展名或内容类型。在 C# 中

我们的生产环境中存在问题,在上次生产升级后,之前上传的 PNG 文件被保存为 JPG 文件扩展名。因此,当我读取该文件时,我无法将 mimetype 设置为 PNG,因为目前它取自 path.getextension,但这是错误的 - 我的实际文件是 PNG 类型。这会导致渲染图像出现问题。

如何从文件字节数组中获取文件扩展名或内容类型。在 C# 中

【问题讨论】:

    标签: c# file mime-types content-type


    【解决方案1】:

    您可以使用Image.RawFormat

    if (ImageFormat.Jpeg.Equals(img.RawFormat))
    {
        // it is JPEG
    }
    else if (ImageFormat.Png.Equals(img.RawFormat))
    {
        // it is PNG
    }
    else if (ImageFormat.Gif.Equals(img.RawFormat))
    {
        // it is GIF
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-29
      • 2014-05-30
      • 2011-06-08
      • 2011-05-27
      • 2013-05-28
      • 1970-01-01
      • 2012-04-19
      • 2014-08-15
      • 2014-02-07
      相关资源
      最近更新 更多