MimeType

master

Get MIME type string from the extension of a file name
onevcat/MimeType

MimeType

Get mime type from a file path or url extension. Like "text/html" for "/var/www/public/index.html" or "image/png" for "/home/user/cat.png".

Installation

Add the url of this repo to your Package.swift:

import PackageDescription

let package = Package(
    name: "YourAwesomeSoftware",
    dependencies: [
        .Package(url: "https://github.com/onevcat/MimeType.git", 
                 majorVersion: 1)
    ]
)

Then run swift build whenever you get prepared.

You could know more information on how to use Swift Package Manager in Apple's official page.

Usage

let path = "/var/www/public/index.html"
let mime = MimeType(path: path).value
// "text/html"

let url = URL(fileURLWithPath: "/home/user/cat.png")
let anotherMime = MimeType(url: url).value
// "image/png"

License

MIT. See the LICENSE file.

Description

  • Swift Tools 3.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Apr 09 2026 09:55:33 GMT-0900 (Hawaii-Aleutian Daylight Time)