Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

guessMIMEType

Infer the MIME type from a file name


Description

This 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.

Usage

guessMIMEType(name, default = NA)

Arguments

name

character vector of file names

default

the value to use if no MIME type is found in the table for the given file name/extension.

Value

A character vector giving the MIME types for each element of name.

Author(s)

Duncan Temple Lang

References

The table of MIME types and extensions was programmatically extracted from http://www.webmaster-toolkit.com/mime-types.shtml or http://reference.sitepoint.com/html/mime-types-full 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.

See Also

Uploading file.

Examples

guessMIMEType(c("foo.txt", "foo.png", "foo.jpeg", "foo.Z", "foo.R"))

 guessMIMEType("foo.bob")
 guessMIMEType("foo.bob", "application/x-binary")

RCurl

General Network (HTTP/FTP/...) Client Interface for R

v1.98-1.3
BSD_3_clause + file LICENSE
Authors
CRAN Team [ctb, cre] (de facto maintainer since 2013), Duncan Temple Lang [aut] (<https://orcid.org/0000-0003-0159-1546>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.