Skip to content

mime: should be able to determine an appropriate extension for a given MIME type #10144

@ghost

Description

Currently it is possible to go from a file extension to a MIME type using TypeForExtension, but the converse is missing. This is useful in applications where it is saving or producing new content of variable type, and needs to know the expected extension.

Proposed API:
func ExtensionsForType(typ string) ([]string, error)

This is the symmetric partner of TypeForExtension, it determines the file extensions for the given type (formatted per RFC 1521, so accepted by ParseMediaType). It does not consider any optional parameters.

The error return value is used solely where the provided MIME type does not parse, distinct from 'no extensions registered', which is an empty slice.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions