Using MimeMapping in ASP.NET Core
The following code should work:
string contentType;
new FileExtensionContentTypeProvider().TryGetContentType(FileName, out contentType);
return contentType ?? "application/octet-stream";
There is a NuGet package MimeTypes which works with .Net Core projects as an alternative to FileExtensionContentTypeProvider
. I'm not aware of any other mime-type resolver package, which works with .Net Core (at least so far).
The usage is simple:
string fileName = "trial.jpg";
string mime = MimeKit.MimeTypes.GetMimeType(fileName);