在Alfresco中,如何测试NodeRef和/或FileInfo对象是否引用二进制文件?

在Alfresco中,如何测试NodeRef和/或FileInfo对象是否引用二进制文件?,alfresco,Alfresco,在Alfresco中,如何测试NodeRef和/或FileInfo对象是否引用二进制文件?(即node.isBinary()) 谢谢,那确实有用。 我也一直在尝试使用ContentService读取文件内容的示例,但我的代码中似乎没有提供ContentService。 任何人都可以知道让ContentService可用的步骤吗? 谢谢首先,看看它是否属于cm:content类型: QName nodeType = nodeService.getType(nodeRef); if (! dicti

在Alfresco中,如何测试NodeRef和/或FileInfo对象是否引用二进制文件?(即node.isBinary())

谢谢,那确实有用。 我也一直在尝试使用ContentService读取文件内容的示例,但我的代码中似乎没有提供ContentService。 任何人都可以知道让ContentService可用的步骤吗?
谢谢

首先,看看它是否属于
cm:content类型

QName nodeType = nodeService.getType(nodeRef);
if (! dictionaryService.isSubClass(nodeType, ContentModel.TYPE_CONTENT)) {
    // Not content, so content can't be binary
   return false;
}
接下来,您需要获取
Content
node属性,它将是一个ContentData对象,最后检查该对象上的mimetype

ContentData contentData = (ContentData)nodeService.getProperty(
                                            nodeRef, ContentModel.PROP_CONTENT);
String mimetype = contentData.getMimetype();
if (mimetype == null) {
    // No idea...
} else if (mimetype.startsWith("text/")) {
    // Shouldn't be binary
    return false;
} else {
    // Most likely binary, but there are a few unusual mimetypes
    //  not under the text/* range that are text...
    return true;
}
您不需要转到ContentService或读取实际内容,只需为其存储元数据即可