| Title: | Map Filenames to MIME Types |
|---|---|
| Description: | Guesses the MIME type from a filename extension using the data derived from /etc/mime.types in UNIX-type systems. |
| Authors: | Yihui Xie [aut, cre] (ORCID: <https://orcid.org/0000-0003-0645-5666>, URL: https://yihui.org), Jeffrey Horner [ctb], Beilei Bian [ctb] |
| Maintainer: | Yihui Xie <[email protected]> |
| License: | GPL |
| Version: | 0.13.1 |
| Built: | 2026-05-23 00:04:42 UTC |
| Source: | https://github.com/yihui/mime |
Look up in the mimemap table for the MIME types based on the extensions of
the given filenames.
guess_type( file, unknown = "application/octet-stream", empty = "text/plain", mime_extra = mimeextra, subtype = "" )guess_type( file, unknown = "application/octet-stream", empty = "text/plain", mime_extra = mimeextra, subtype = "" )
file |
a character vector of filenames, or filename extensions |
unknown |
the MIME type to return when the file extension was not found in the table |
empty |
the MIME type for files that do not have extensions |
mime_extra |
a named character vector of the form |
subtype |
a character vector of MIME subtypes, which should be of the
same length as |
library(mime) # well-known file types guess_type(c("a/b/c.html", "d.pdf", "e.odt", "foo.docx", "tex")) # not in the standard table, but in mimeextra guess_type(c("a.md", "b.R"), mime_extra = NULL) guess_type(c("a.md", "b.R")) # override the standard MIME table (tex is text/x-tex by default) guess_type("tex", mime_extra = c(tex = "text/plain")) # unknown extension 'zzz' guess_type("foo.zzz") # force unknown types to be plain text guess_type("foo.zzz", unknown = "text/plain") # empty file extension guess_type("Makefile") # we know it is a plain text file guess_type("Makefile", empty = "text/plain") # subtypes guess_type(c("abc.html", "def.htm"), subtype = c("charset=UTF-8", ""))library(mime) # well-known file types guess_type(c("a/b/c.html", "d.pdf", "e.odt", "foo.docx", "tex")) # not in the standard table, but in mimeextra guess_type(c("a.md", "b.R"), mime_extra = NULL) guess_type(c("a.md", "b.R")) # override the standard MIME table (tex is text/x-tex by default) guess_type("tex", mime_extra = c(tex = "text/plain")) # unknown extension 'zzz' guess_type("foo.zzz") # force unknown types to be plain text guess_type("foo.zzz", unknown = "text/plain") # empty file extension guess_type("Makefile") # we know it is a plain text file guess_type("Makefile", empty = "text/plain") # subtypes guess_type(c("abc.html", "def.htm"), subtype = c("charset=UTF-8", ""))
The data mimemap is a named character vector that stores the filename
extensions and the corresponding MIME types, e.g. c(html = 'text/html', pdf = 'application/pdf', ...). The character vector mime:::mimeextra stores
some additional types that we know, such as Markdown files (.md), or R
scripts (.R).
The file /etc/mime.types on Debian.
str(as.list(mimemap)) mimemap["pdf"] mimemap[c("html", "js", "css")] # additional MIME types (not exported) mime:::mimeextrastr(as.list(mimemap)) mimemap["pdf"] mimemap[c("html", "js", "css")] # additional MIME types (not exported) mime:::mimeextra
This function parses the HTML form data from a Rook environment (an HTTP POST request).
parse_multipart(env)parse_multipart(env)
env |
the HTTP request environment |
A named list containing the values of the form data, and the files
uploaded are saved to temporary files (the temporary filenames are
returned). It may also be NULL if there is anything unexpected in the
form data, or the form is empty.
This function was borrowed from https://github.com/jeffreyhorner/Rook/ with slight modifications.