Search code examples
c#.netmimesystem.net

What values are allowed for the IsMimeMultipartContent subtype parameter


I am working on an image file upload method in Web API 2 and have noticed that the extension method IsMimeMultipartContent can take a string subtype parameter, as documented here:

https://learn.microsoft.com/en-us/previous-versions/aspnet/hh835657(v%3Dvs.118)

However, the only specification for this parameter is "The MIME multipart subtype to match." and no examples of format are present in the documentation.

I presume that, as a string value, it must take a value such as "image/png". Is there a way for it to check against all images, such as using a wildcard value "image/*" or value separated by semicolons on commas? What is the required format of this parameter?

If it can't check for multiple MIME types, is there a better way to check?


Solution

  • The string subtype parameter is a multipart MIME subtype. It is appended to the mime type multipart/ and compared to the incoming MIME type of the data, as such:

    content.Headers.ContentType.MediaType.Equals("multipart/" + subtype, StringComparison.OrdinalIgnoreCase)
    

    This has been taken from the source code, publicly visible here.

    It will not work with image/png because it looks for multipart/<subtype> MIME types.

    Typical valid subtypes are form-data and byteranges. More can be read about MIME types and subtypes here.