FileController - content disposition

This commit is contained in:
Pavel Vesely
2020-12-15 10:49:48 +01:00
parent deaaa74fc8
commit 07711c082e
5 changed files with 93 additions and 27 deletions

View 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);
}
}
}

View File

@ -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;
}
}
}