Skip to content

Add GetContentType() to Attachment API for retrieving OPC content types#453

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/add-retrieve-attachment-types
Draft

Add GetContentType() to Attachment API for retrieving OPC content types#453
Copilot wants to merge 4 commits intomasterfrom
copilot/add-retrieve-attachment-types

Conversation

Copy link

Copilot AI commented Feb 23, 2026

lib3mf was parsing [Content_Types].xml internally but discarding the data, making it impossible for API consumers to determine the MIME type of package attachments (e.g., distinguishing PNG from JPEG thumbnails).

Changes

OPC layer

  • COpcPackageReader::readContentTypes() now populates two maps: m_ContentTypes (Override entries, keyed by exact part path) and m_ContentTypesByExtension (Default entries, keyed by extension)
  • New getContentType(path) method: checks Override entries first, falls back to extension-based lookup
  • IOpcPackageReader interface and CKeyStoreOpcPackageReader updated accordingly

Model layer

  • CModelAttachment gains a m_sContentType field with getContentType()/setContentType() accessors
  • NMR_ModelReader_3MF_Native populates content type when loading thumbnail, texture, and custom attachments

API / bindings

  • IAttachment::GetContentType() added as a pure virtual, returning the content type string (empty for programmatically-created attachments not read from a package)
  • C ABI: lib3mf_attachment_getcontenttype
  • Updated: C++ implicit binding, C++ dynamic binding (typedef, wrapper table, load/lookup)

Usage

auto reader = model->QueryReader("3mf");
reader->ReadFromFile("model.3mf");

auto thumbnail = model->GetPackageThumbnailAttachment();
std::string ct = thumbnail->GetContentType(); // e.g. "image/png" or "image/jpeg"
Original prompt

This section details on the original issue you should resolve

<issue_title>Add a way to retrieve Attachment Content Types</issue_title>
<issue_description>Currenty lib3mf does not parse the [Content_Types].xml in the package.
It would be great to properly parse this and retrieve content types of Package Parts via Lib3MF API.

Use cases are plenty, but for example:
At the moment it is hard to distinguish package thumbnails, if they are meant to be PNG or JPEGs.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 23, 2026 14:44
…rom [Content_Types].xml

Co-authored-by: martinweismann <30837766+martinweismann@users.noreply.github.com>
Co-authored-by: martinweismann <30837766+martinweismann@users.noreply.github.com>
…acked build artifacts

Co-authored-by: martinweismann <30837766+martinweismann@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ability to retrieve attachment content types Add GetContentType() to Attachment API for retrieving OPC content types Feb 23, 2026
Copilot AI requested a review from martinweismann February 23, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a way to retrieve Attachment Content Types

2 participants