How to map ADF media in a comment to a specific attachmentId when mediaInline has no fileName and ADF id ≠ attachment id?

I’m reading Jira Cloud comment bodies in ADF. Media nodes (e.g. mediaSingle, mediaInline) carry an attrs.id, but that value is not the same as the REST attachments’ attachmentId. In addition, mediaInline does not expose a fileName, so filename matching isn’t an option there.

What I need: a supported way to link each media node in the ADF comment body to the corresponding Jira attachment entity so I can get its attachmentId (the one used by /rest/api/3/attachment/{id}), or at least a reliable mapping.

Questions:

Is there an official API to resolve an ADF media node (given id, collection, occurrenceKey) to the Jira attachment and obtain its attachmentId?

If not, what is the recommended approach to map mediaInline (no fileName) to an attachment?

Are these ADF attrs.id values the Media Platform “fileId”? If yes, is there a documented bridge from Media Platform fileId → Jira attachmentId?

Any best practices or sample code for this mapping?

Right now, I’ve implemented a workaround: when a new comment is created, I check all attachments on the issue and mark those that I haven’t yet linked to any comment (using a custom property). This lets me guess which attachment is referenced by a new mediaInline.

This works most of the time but feels fragile and bug-prone (especially with concurrent edits, multiple attachments with the same filename, or re-used files).

So I’d really like to know: is there an official, reliable way to link mediaInline → attachmentId, instead of relying on this workaround?

Thanks!