Name
global.ContentTypeValidator
Description
For a given system property which lists out supported content types, this Script Inlcude checks to make sure the associated attachment stored (passed into class as a GlideRecord) has the correct content_type.
Script
var ContentTypeValidator = Class.create();
ContentTypeValidator.prototype = {
defaultSupportedContentTypes: "image/svg+xml",
initialize: function() {},
isValidType: function(attachment /*GlideRecord*/, userDefinedSupportedContentTypes /*Array*/) {
if (gs.nil(attachment)) {
return false;
}
var contentType = attachment.getValue("content_type");
if (gs.nil(userDefinedSupportedContentTypes) || !Array.isArray(userDefinedSupportedContentTypes)) {
userDefinedSupportedContentTypes = this.defaultSupportedContentTypes;
}
if (userDefinedSupportedContentTypes.indexOf(contentType) == -1) {
return false;
}
return true;
}
};
Sys ID
85ff0a4c5b6f001001fb0c370581c7fd