-- G --
guess_type()
-- M --
mimemap
-- P --
parse_multipart()
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 = ""
)
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"))
#> [1] "text/html"
#> [2] "application/pdf"
#> [3] "application/vnd.oasis.opendocument.text"
#> [4] "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
#> [5] "text/plain"
# not in the standard table, but in mimeextra
guess_type(c("a.md", "b.R"), mime_extra = NULL)
#> [1] "text/markdown" "application/octet-stream"
guess_type(c("a.md", "b.R"))
#> [1] "text/markdown" "text/plain"
# override the standard MIME table (tex is text/x-tex by default)
guess_type("tex", mime_extra = c(tex = "text/plain"))
#> [1] "text/plain"
# unknown extension 'zzz'
guess_type("foo.zzz")
#> [1] "application/octet-stream"
# force unknown types to be plain text
guess_type("foo.zzz", unknown = "text/plain")
#> [1] "text/plain"
# empty file extension
guess_type("Makefile")
#> [1] "text/plain"
# we know it is a plain text file
guess_type("Makefile", empty = "text/plain")
#> [1] "text/plain"
# subtypes
guess_type(c("abc.html", "def.htm"), subtype = c("charset=UTF-8", ""))
#> [1] "text/html; charset=UTF-8" "text/html"
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))
#> List of 1548
#> $ % : chr "application/x-trash"
#> $ ~ : chr "application/x-trash"
#> $ 123 : chr "application/vnd.lotus-1-2-3"
#> $ 1905.1 : chr "application/vnd.ieee.1905"
#> $ 1clr : chr "application/clr"
#> $ 1km : chr "application/vnd.1000minds.decision-model+xml"
#> $ 210 : chr "application/p21"
#> $ 3dm : chr "text/vnd.in3d.3dml"
#> $ 3dml : chr "text/vnd.in3d.3dml"
#> $ 3mf : chr "application/vnd.ms-3mfdocument"
#> $ 3tz : chr "application/vnd.maxar.archive.3tz+zip"
#> $ 726 : chr "audio/32kadpcm"
#> $ 7z : chr "application/x-7z-compressed"
#> $ a : chr "text/vnd.a"
#> $ a2l : chr "application/A2L"
#> $ aa3 : chr "audio/ATRAC3"
#> $ aac : chr "audio/aac"
#> $ aal : chr "audio/ATRAC-ADVANCED-LOSSLESS"
#> $ abc : chr "text/vnd.abc"
#> $ abw : chr "application/x-abiword"
#> $ ac : chr "application/pkix-attr-cert"
#> $ ac2 : chr "application/vnd.banana-accounting"
#> $ ac3 : chr "audio/ac3"
#> $ acc : chr "application/vnd.americandynamics.acc"
#> $ acn : chr "audio/asc"
#> $ acu : chr "application/vnd.acucobol"
#> $ acutc : chr "application/vnd.acucorp"
#> $ adts : chr "audio/aac"
#> $ aep : chr "application/vnd.audiograph"
#> $ afp : chr "application/vnd.afpc.modca"
#> $ age : chr "application/vnd.age"
#> $ ahead : chr "application/vnd.ahead.space"
#> $ ai : chr "application/postscript"
#> $ aif : chr "audio/x-aiff"
#> $ aifc : chr "audio/x-aiff"
#> $ aiff : chr "audio/x-aiff"
#> $ aion : chr "application/vnd.veritone.aion+json"
#> $ ait : chr "application/vnd.dvb.ait"
#> $ alc : chr "chemical/x-alchemy"
#> $ ami : chr "application/vnd.amiga.ami"
#> $ aml : chr "application/AML"
#> $ amlx : chr "application/automationml-amlx+zip"
#> $ amr : chr "audio/AMR"
#> $ AMR : chr "audio/AMR"
#> $ anx : chr "application/annodex"
#> $ apex : chr "application/vnd.apexlang"
#> $ apexlang : chr "application/vnd.apexlang"
#> $ apk : chr "application/vnd.android.package-archive"
#> $ apkg : chr "application/vnd.anki"
#> $ apng : chr "image/apng"
#> $ appcache : chr "text/cache-manifest"
#> $ apr : chr "application/vnd.lotus-approach"
#> $ apxml : chr "application/auth-policy+xml"
#> $ arrow : chr "application/vnd.apache.arrow.file"
#> $ arrows : chr "application/vnd.apache.arrow.stream"
#> $ art : chr "image/x-jg"
#> $ artisan : chr "application/vnd.artisan+json"
#> $ asc : chr "application/pgp-keys"
#> $ ascii : chr "text/vnd.ascii-art"
#> $ asf : chr "application/vnd.ms-asf"
#> $ asice : chr "application/vnd.etsi.asic-e+zip"
#> $ asics : chr "application/vnd.etsi.asic-s+zip"
#> $ asn : chr "chemical/x-ncbi-asn1"
#> $ aso : chr "application/vnd.accpac.simply.aso"
#> $ ass : chr "audio/aac"
#> $ at3 : chr "audio/ATRAC3"
#> $ atc : chr "application/vnd.acucorp"
#> $ atf : chr "application/ATF"
#> $ atfx : chr "application/ATFX"
#> $ atom : chr "application/atom+xml"
#> $ atomcat : chr "application/atomcat+xml"
#> $ atomdeleted : chr "application/atomdeleted+xml"
#> $ atomsrv : chr "application/atomserv+xml"
#> $ atomsvc : chr "application/atomsvc+xml"
#> $ atx : chr "audio/ATRAC-X"
#> $ atxml : chr "application/ATXML"
#> $ au : chr "audio/basic"
#> $ auc : chr "application/tamp-apex-update-confirm"
#> $ avci : chr "image/avci"
#> $ avcs : chr "image/avcs"
#> $ avi : chr "video/x-msvideo"
#> $ avif : chr "image/avif"
#> $ awb : chr "audio/AMR-WB"
#> $ AWB : chr "audio/AMR-WB"
#> $ axa : chr "audio/annodex"
#> $ axv : chr "video/annodex"
#> $ azf : chr "application/vnd.airzip.filesecure.azf"
#> $ azs : chr "application/vnd.airzip.filesecure.azs"
#> $ azv : chr "image/vnd.airzip.accelerator.azv"
#> $ azw3 : chr "application/vnd.amazon.mobi8-ebook"
#> $ b : chr "chemical/x-molconn-Z"
#> $ b16 : chr "image/vnd.pco.b16"
#> $ bak : chr "application/x-trash"
#> $ bar : chr "application/vnd.qualcomm.brew-app-res"
#> $ bary : chr "model/vnd.bary"
#> $ bat : chr "application/x-msdos-program"
#> $ bcpio : chr "application/x-bcpio"
#> $ bdm : chr "application/vnd.syncml.dm+wbxml"
#> $ bed : chr "application/vnd.realvnc.bed"
#> [list output truncated]
mimemap["pdf"]
#> pdf
#> "application/pdf"
mimemap[c("html", "js", "css")]
#> html js css
#> "text/html" "text/javascript" "text/css"
# additional MIME types (not exported)
mime:::mimeextra
#> jsonp r rd
#> "application/javascript" "text/plain" "text/plain"
#> rmd rnw rproj
#> "text/x-markdown" "text/x-sweave" "text/rstudio"
#> scss
#> "text/css"
This function parses the HTML form data from a Rook environment (an HTTP POST request).
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.