Search code examples
fileuploadmime-typescontent-typeform-data

Form Data: wrong Content-Type for .p7m files


I need to save a file with correct MimeType for .p7m files (application/pkcs7-mime) via form upload to the server. In the request I noticed that Content-Type is wrong:

------WebKitFormBoundaryaglEgtBJlb65v7d5 Content-Disposition: form-data; name="file0"; filename="getmymimeplease.p7m" Content-Type: application/pkcs7

it should be:

Content-Type: application/pkcs7-mime

How is possible that the '-mime' part is missing (or truncated) ?


Solution

  • This is usually controlled by OS and/or Browser. On windows, this is set in the registry, in HKEY_CLASSES_ROOT\.<fileextension>, e.g. HKEY_CLASSES_ROOT\.p7m, in the Field Content Type:

    Sample for .p7m

    So in the end, this is controlled by the client. So if there are several possible mime types for the same extension, you need to cover that in your server code (accept or decline, convert to your default or not)