📜  如何在 c# 代码示例中从 base64 获取文件类型

📅  最后修改于: 2022-03-11 14:49:00.800000             🧑  作者: Mango

代码示例1
/// 
/// To demonstrate extraction of file extension from base64 string.
/// 
/// base64 string.
/// Henceforth file extension from string.
public static string GetFileExtension(string base64String)
{
var data = base64String.Substring(0, 5);

switch (data.ToUpper())
 {
     case "IVBOR":
        return "png";
     case "/9J/4":
         return "jpg";
     case "AAAAF":
         return "mp4";
     case "JVBER":
         return "pdf";
     case "AAABA":
         return "ico";
     case "UMFYI":
         return "rar";
     case "E1XYD":
         return "rtf";
     case "U1PKC":
        return "txt";
     case "MQOWM":
     case "77U/M":
        return "srt";
     default:
        return string.Empty;
 }
}