logo

NJP

Attachment MIME type mapping

SN Scout · Feb 08, 2021 · article

Maybe you've had this experience:

A user uploads an attachment to a ServiceNow record. The user saves the record, but the attachment disappears. Or perhaps the user attempts to upload an attachment and receives an error stating, "...File type not permitted or mime type does not match the file content."

If your instance has configured the 'glide.attachment.extensions' property, you may be attempting to upload a file with an extension that doesn't match one in the defined list. The easy fix there is to get the extension added to the property.

The other half of that error though refers to the MIME type of the file. No, not the voiceless street performers we've come to know and love (usually stuck in an invisible box). Instead, if your instance has implemented the security best practice of enabling MIME type validation, the file you're uploading doesn't match the expected MIME type.

Ok, ok. What are MIME types anyway? MIME stands for Multipurpose Internet Mail Extensions. This is a header check on the file (not the extension) that checks for what content type is actually contained

within the file. An industry standard maintained by IANA, MIME types are a type/subtype combo that define what general category and specific subcategory a file type falls into. If you take a peak at the 'sys_attachment' table in your ServiceNow instance, you'll see that there is a content type associated with each attachment.

When a ServiceNow instance does a check on an attachment, it compares the file's extension (e.g. .txt) to the expected MIME type (e.g. text/plain). The error, "...mime type does not match the file content." arises when the pre-mapped list of file extensions to MIME types in ServiceNow does not contain a match for your new attachment. You can see a list of pre-configured MIME types by looking at the '/sys_attachment_icon_rule_list.do' list in your instance.

So what do we do when file extensions aren't an issue and our MIME type isn't recognized? Well, we have to map the extension to a MIME type. If it doesn't yet exist, you need to create a system property called 'glide.security.mime_type.extension_mapping'. The values are comma separated using a syntax that combines the extension with the MIME type/subtype format for example: dat=application/octet-stream,dat=text/plain.

If you're not sure what the file type is, you can use sites like https://checkfiletype.com/ to figure it out, then look it up on the IANA Media Type page.

View original source

https://snscout.blogspot.com/2021/02/attachment-mime-type-mapping.html