code: public static MimeType getMimeType(Resource resource) {
          MimeType result = null;
          if (resource != null) {
              ResourceHandle handle = ResourceHandle.use(resource);
              result = getMimeType(handle.getProperty(ResourceUtil.PROP_MIME_TYPE, ""));
              if (result == null) {
                  String name = resource.getName();
                  if (ResourceUtil.CONTENT_NODE.equals(name)) {
                      result = getParentMimeType(resource);
                  } else {
                      result = getContentMimeType(resource);
                      if (result == null) {
                          String filename = getResourceName(resource);
                          result = getMimeType(filename);
                      }
                  }
              }
          }
          return result;
      }
docs: Detects the mime type of a binary resource (nt:file, nt:resource or another asset type).
  
  @param resource the binary resource
  @return he detected mime type or 'null' if the detection was not successful