Skip to content

Commit d949e89

Browse files
authored
Merge pull request SciSharp#1346 from adenchen123/master
Handle URLs in GetFileContentType and add null check
2 parents 3e7b1f7 + 062ad78 commit d949e89

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/Infrastructure/BotSharp.Abstraction/Files/Utilities/FileUtility.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ public static BinaryData BuildBinaryDataFromFile(IFormFile file)
6565

6666
public static string GetFileContentType(string fileName)
6767
{
68+
if (string.IsNullOrEmpty(fileName))
69+
{
70+
return string.Empty;
71+
}
72+
73+
// For URLs (e.g. signed S3/CloudFront URLs with query strings), extract the path portion
74+
// so that FileExtensionContentTypeProvider can correctly resolve the extension.
75+
if (Uri.TryCreate(fileName, UriKind.Absolute, out var uri)
76+
&& (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps))
77+
{
78+
fileName = uri.AbsolutePath;
79+
}
80+
6881
string contentType;
6982
var provider = new FileExtensionContentTypeProvider();
7083
if (!provider.TryGetContentType(fileName, out contentType))

0 commit comments

Comments
 (0)