Is there a built-in way to get the standard extension of a given MIME type in Delphi (XE7)?
I'm looking for the easiest and most general way to implement a function that would be called like this:
fileExt := GetExtension('text/xml');
It seems Indy has a built in function for that, on TIdThreadSafeMimeTable:
Uses
IdCustomHTTPServer;
function GetMIMETypeDefaultExtension(const aMIMEType: String): String;
var
mimetable: TIdThreadSafeMimeTable;
Begin
if not(aMIMEType.Trim.IsEmpty) then
Begin
mimetable := TIdThreadSafeMimeTable.Create(true);
try
result := mimetable.GetDefaultFileExt(aMIMEType);
finally
mimetable.Free;
end
End
else
result := '';
End;
Edit: function fixed to use TIdThreadSafeMimeTable directly without custom http server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With