Static Methodvapor 4.114.1Vapor

fileExtension(_:)

Creates a MediaType from a file extension, if possible.

HTTPMediaType.swift:165
static func fileExtension(_ ext: String) -> HTTPMediaType?

Parameters

ext

File extension (ie., “txt”, “json”, “html”).

Returns

Newly created MediaType, nil if none was found.

guard let mediaType = MediaType.fileExtension("txt") else { ... }