Debian Codegraph @

man/guessMIMEType.Rd

raw
1 \name{guessMIMEType}
2 \alias{guessMIMEType}
3 \title{Infer the MIME type from a file name}
4 \description{
5 This function returns the MIME type, i.e. part of the value
6 used in the Content-Type for an HTTP request/response
7 or in email to identify the nature of the content.
8 This is a string such as "text/plain" or "text/xml"
9 or "image/png".
10
11 The function consults an R object constructed
12 by reading a Web site of known MIME types (not necessarily all)
13 and matching the extension of the file name to the names of that table.
14 }
15 \usage{
16 guessMIMEType(name, default = NA)
17 }
18 \arguments{
19 \item{name}{character vector of file names}
20 \item{default}{the value to use if no MIME type is found in the table
21 for the given file name/extension.}
22 }
23 \value{
24 A character vector giving the MIME types for each element of \code{name}.
25 }
26 \references{
27 The table of MIME types and extensions was programmatically extracted
28 from \samp{http://www.webmaster-toolkit.com/mime-types.shtml} with
29 \code{
30 tbls = readHTMLTable("http://www.webmaster-toolkit.com/mime-types.shtml")
31 tmp = tbls[[1]][-1,]
32 mimeTypeExtensions = structure(as.character(tmp[[2]]), names = gsub("^\\.", "", tmp[[1]]))
33 save(mimeTypeExtensions, file = "data/mimeTypeExtensions.rda")
34 }
35 The IANA list is not as convenient to programmatically compile.
36 %\url{http://www.ltsw.se/knbase/internet/mime.htp}
37 }
38 \author{
39 Duncan Temple Lang
40 }
41
42
43 \seealso{
44 Uploading file.
45 }
46 \examples{
47 guessMIMEType(c("foo.txt", "foo.png", "foo.jpeg", "foo.Z", "foo.R"))
48
49 guessMIMEType("foo.bob")
50 guessMIMEType("foo.bob", "application/x-binary")
51 }
52 \keyword{IO}
53