Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ public static BinaryData BuildBinaryDataFromFile(IFormFile file)

public static string GetFileContentType(string fileName)
{
if (string.IsNullOrEmpty(fileName))
{
return string.Empty;
}

// For URLs (e.g. signed S3/CloudFront URLs with query strings), extract the path portion
// so that FileExtensionContentTypeProvider can correctly resolve the extension.
if (Uri.TryCreate(fileName, UriKind.Absolute, out var uri)
&& (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps))
{
fileName = uri.AbsolutePath;
}

string contentType;
var provider = new FileExtensionContentTypeProvider();
if (!provider.TryGetContentType(fileName, out contentType))
Expand Down
Loading