From b47a29af5e41519e520e067640e48d513d8a91d5 Mon Sep 17 00:00:00 2001
From: mwoda <84077698+mwwoda@users.noreply.github.com>
Date: Wed, 17 Jul 2024 19:47:49 +0200
Subject: [PATCH 1/2] fix: remove `Microsoft.AspNetCore.StaticFiles` and
`System.Web` dependencies
---
Box.V2.Core/Box.V2.Core.csproj | 1 -
Box.V2/Box.V2.csproj | 5 ++--
Box.V2/Utility/ContentTypeMapper.cs | 41 ++++++++++++++++++++++++-----
3 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/Box.V2.Core/Box.V2.Core.csproj b/Box.V2.Core/Box.V2.Core.csproj
index 8eb6c080b..d9725f136 100644
--- a/Box.V2.Core/Box.V2.Core.csproj
+++ b/Box.V2.Core/Box.V2.Core.csproj
@@ -37,7 +37,6 @@
-
diff --git a/Box.V2/Box.V2.csproj b/Box.V2/Box.V2.csproj
index 99dd3b0f8..16e24f4e1 100644
--- a/Box.V2/Box.V2.csproj
+++ b/Box.V2/Box.V2.csproj
@@ -1,4 +1,4 @@
-
+
@@ -97,7 +97,6 @@
..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll
-
@@ -376,4 +375,4 @@
-
\ No newline at end of file
+
diff --git a/Box.V2/Utility/ContentTypeMapper.cs b/Box.V2/Utility/ContentTypeMapper.cs
index 11f072a28..eda229e84 100644
--- a/Box.V2/Utility/ContentTypeMapper.cs
+++ b/Box.V2/Utility/ContentTypeMapper.cs
@@ -1,24 +1,51 @@
+using System.Collections.Generic;
+using System.IO;
+
namespace Box.V2.Utility
{
+ ///
+ /// Utility class for determining Content-Type header. Should only be used internally by the SDK.
+ ///
public static class ContentTypeMapper
{
+ private static readonly Dictionary _mimeMapping = new Dictionary()
+ {
+ { ".jpe", "image/jpeg" },
+ { ".jpeg", "image/jpeg" },
+ { ".jpg", "image/jpeg" },
+ { ".bmp", "image/bmp" },
+ { ".png", "image/png" },
+ { ".gif", "image/gif" },
+ { ".webp", "image/webp" },
+ };
+
+ ///
+ /// Get Content-Type header from a filename. Supports most common image formats. Should only be used internally by the SDK.
+ ///
+ /// full filename with extension
+ /// Content-Type header as a string
public static string GetContentTypeFromFilename(string filename)
{
const string DefaultContentType = "application/octet-stream";
var contentType = DefaultContentType;
-#if NETSTANDARD2_0
- var provider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider();
-
- if (provider.TryGetContentType(filename, out var contentTypeFromFile))
+ if (TryGetContentType(filename, out var contentTypeFromFile))
{
contentType = contentTypeFromFile;
}
-#else
- contentType = System.Web.MimeMapping.GetMimeMapping(filename);
-#endif
return contentType;
}
+
+ private static bool TryGetContentType(string path, out string contentType)
+ {
+ var extension = Path.GetExtension(path);
+ if (extension == null)
+ {
+ contentType = null;
+ return false;
+ }
+ return _mimeMapping.TryGetValue(extension, out contentType);
+ }
}
}
From 8ef0c46ff47dfb8c21cba5b28493284ca226e7bd Mon Sep 17 00:00:00 2001
From: mwoda <84077698+mwwoda@users.noreply.github.com>
Date: Wed, 17 Jul 2024 20:25:04 +0200
Subject: [PATCH 2/2] git attribute fix
---
.gitattributes | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitattributes b/.gitattributes
index cfb5d9a3d..dffe9f2a7 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,2 +1,3 @@
# Set default behaviour to automatically normalize line endings.
* text=auto
+*.cs text eol=crlf
\ No newline at end of file