FileController - content disposition
This commit is contained in:
31
Oqtane.Server/Extensions/MimeUtilities.cs
Normal file
31
Oqtane.Server/Extensions/MimeUtilities.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Extensions
|
||||
{
|
||||
public static class MimeUtilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Return Mime content type based on file extension
|
||||
/// </summary>
|
||||
/// <param name="fileName">File name</param>
|
||||
public static string GetMimeType(string fileName)
|
||||
{
|
||||
var provider = new FileExtensionContentTypeProvider();
|
||||
|
||||
if (!provider.TryGetContentType(fileName, out var contentType))
|
||||
contentType = "application/octet-stream";
|
||||
// we can add additional mappings here
|
||||
|
||||
return contentType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return Mime content type based on file extension
|
||||
/// </summary>
|
||||
public static string GetMimeType(this File file)
|
||||
{
|
||||
return GetMimeType(file?.Name);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Extensions
|
||||
{
|
||||
@ -15,17 +16,5 @@ namespace Oqtane.Extensions
|
||||
|
||||
return list.Any(f => s.StartsWith(f));
|
||||
}
|
||||
|
||||
public static string GetMimeType(this string fileName)
|
||||
{
|
||||
var provider = new FileExtensionContentTypeProvider();
|
||||
|
||||
if (!provider.TryGetContentType(fileName, out var contentType))
|
||||
{
|
||||
contentType = "application/octet-stream";
|
||||
}
|
||||
|
||||
return contentType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user