guessMIMEType.RdThis function returns the MIME type, i.e. part of the value used in the Content-Type for an HTTP request/response or in email to identify the nature of the content. This is a string such as "text/plain" or "text/xml" or "image/png".
The function consults an R object constructed by reading a Web site of known MIME types (not necessarily all) and matching the extension of the file name to the names of that table.
guessMIMEType(name, default = NA)A character vector giving the MIME types for each element of name.
The table of MIME types and extensions was programmatically extracted
from http://www.webmaster-toolkit.com/mime-types.shtml with
tbls = readHTMLTable("http://www.webmaster-toolkit.com/mime-types.shtml")
tmp = tbls[[1]][-1,]
mimeTypeExtensions = structure(as.character(tmp[[2]]), names = gsub("^\.", "", tmp[[1]]))
save(mimeTypeExtensions, file = "data/mimeTypeExtensions.rda")
The IANA list is not as convenient to programmatically compile.
Uploading file.
guessMIMEType(c("foo.txt", "foo.png", "foo.jpeg", "foo.Z", "foo.R"))
#> foo.txt foo.png foo.jpeg
#> "text/plain" "image/png" "image/jpeg"
#> foo.Z foo.R
#> "application/x-compress" "text/R-code"
guessMIMEType("foo.bob")
#> foo.bob
#> NA
guessMIMEType("foo.bob", "application/x-binary")
#> foo.bob
#> "application/x-binary"