I have a task of base64 decoder. As you know base64 does not contain any inforamation about source file name, but first 5 symbols do contain information about file type. I already have a function that returns type from base64 string. Here it is.
string GetFileTypeByBase64(string base64)
{
var data = base64.Substring(0, 5);
switch (data.ToUpper())
{
case "IVBOR":
return ".png";
case "/9J/4":
return ".jpg";
case "AAAAI":
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 "." + data;
}
}
And here is my question : How do I know the file I have in base64 string is mp3 or wav? (Will also be grateful if you provide other file type sign)
In relation to your switch statement, the string for a WAV file would be "UklGR" and the string for an MP3 file would be "SUQzB".
These strings are the bytes of the file itself and so this string is essentially the first part of the file header.