PSMimeTypes is a PowerShell module that provides functionality for resolving MIME types from file extensions and filenames. It utilizes the JSHTTP Mime-DB for MIME type lookups. By default, the module fetches the database from the internet but also allows importing a local JSON copy for offline usage.
- Resolve MIME types from file extensions.
- Extract file extensions from filenames and determine the corresponding MIME type.
- Import a local MIME database for offline lookups.
To use PSMimeTypes, import the module into your PowerShell session:
Install-Module "PSMimeTypes"
Import-Module "PSMimeTypes"
Convert-ExtensionToMimeType -Extension "jpg"
# Output: image/jpeg
'.jpg' | Convert-ExtensionToMimeType
# Output: image/jpeg
Convert-FileNameToMimeType -FileName "document.pdf"
# Output: application/pdf
'C:\Users\MyUser\MyDocument\test.pdf' | Convert-FileNameToMimeType
# Output: application/pdf
Import-MimeDBFromFile -Path "C:\path\to\mime-db.json"
# Output: True (if successful) or False (if failed)
This module relies on:
- JSHTTP Mime-DB, a comprehensive and community-maintained MIME type database.
Contributions are welcome! If you'd like to improve this module, feel free to submit a pull request or open an issue.
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
This project makes use of the JSHTTP Mime-DB. Special thanks to the maintainers and contributors of the Mime-DB for their work in maintaining an extensive and accurate MIME type database.
- Kieron Morris (t3hn3rd) - kjm@kieronmorris.me