Skip to content

Instantly share code, notes, and snippets.

@scattered-code
Created September 21, 2020 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scattered-code/ae719134c3163c9b3c4bd0841920ff18 to your computer and use it in GitHub Desktop.
Save scattered-code/ae719134c3163c9b3c4bd0841920ff18 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
namespace Web.Infrastructure
{
public static class RequestHelpers
{
public static string GetBoundary(string contentType)
{
var elements = contentType.Split(' ');
var element = elements.First(e => e.StartsWith("boundary="));
var boundary = element.Substring("boundary=".Length);
if (boundary.Length >= 2 && boundary[0] == '"' && boundary[^1] == '"')
boundary = boundary[1..^1];
return boundary;
}
public static bool IsMultipartContentType(string contentType) => !string.IsNullOrEmpty(contentType) && contentType.IndexOf("multipart/", StringComparison.OrdinalIgnoreCase) >= 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment