Detect file type of container item

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Parser MCP server lets your agent work with files on your machine; they are never uploaded. It runs in Docker: replace /path/to/documents with the folder it may use.

claude mcp add groupdocs-parser -- docker run --rm -i -v /path/to/documents:/data ghcr.io/groupdocs-parser/parser-net-mcp:latest
Folders, licensing and more →

GroupDocs.Parser provides the functionality to detect a file type of container items by detectFileType(FileTypeDetectionMode) method.

FileTypeDetectionMode parameter provides the ability to control file type detection:

  • Default. The file type is detected by the file extension; if the file extension isn’t recognized, the file type is detected by the file content.
  • Extension. The file type is detected only by the file extension.
  • Content. The file type is detected only by the file content.

Here are the steps to detect a file type of container items:

The following example shows how to detect a file type of container items:

// Create an instance of Parser class
try (Parser parser = new Parser(Constants.SampleZip)) {
    // Extract attachments from the container
    Iterable<ContainerItem> attachments = parser.getContainer();
    // Check if container extraction is supported
    if (attachments == null) {
        System.out.println("Container extraction isn't supported");
    }
    // Iterate over attachments
    for (ContainerItem item : attachments) {
        // Detect the file type
        FileType fileType = item.detectFileType(FileTypeDetectionMode.Default);
        // Print the name and file type
        System.out.println(String.format("%s: %s", item.getName(), fileType));
    }
}

More resources

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document parser App

Along with full featured Java library we provide simple, but powerful free Apps.

You are welcome to extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Parser App.