Work with attachments

Description

Work with attachments

Usage

1
2
3
4
5
6
7
8
doc_attach_create(cushion, dbname, docid, attachment, attname, as = "list",
  ...)

doc_attach_info(cushion, dbname, docid, attname, ...)

doc_attach_get(cushion, dbname, docid, attname, type = "raw", ...)

doc_attach_delete(cushion, dbname, docid, attname, as = "list", ...)

Arguments

cushion

A Cushion object. Required.

dbname

(charcter) Database name. Required.

docid

(charcter) Document ID. Required.

attachment

(charcter) A file name. Required.

attname

(charcter) Attachment name. Required.

as

(character) One of list (default) or json

...

Curl args passed on to one of the HTTP verbs (e.g,. GET, POST, PUT, etc.)

type

(character) one of raw (default) or text. required.

Details

Methods:

  • doc_attach_create - create an attachment

  • doc_attach_info - get info (headers) for an attachment

  • doc_attach_get - get an attachment. this method does not attempt to read the object into R, but only gets the raw bytes or plain text. See examples for how to read some attachment types

  • doc_attach_delete - delete and attachment

Value

JSON as a character string or a list (determined by the as parameter)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
## Not run: 
(x <- Cushion$new())

if ("drinksdb" %in% db_list(x)) {
  invisible(db_delete(x, dbname="drinksdb"))
}
db_create(x, dbname='drinksdb')

# create an attachment on an existing document
## create a document first
doc <- '{"name":"stuff", "drink":"soda"}'
doc_create(x, dbname="drinksdb", doc=doc, docid="asoda")

## create a csv attachment
row.names(mtcars) <- NULL
file <- tempfile(fileext = ".csv")
write.csv(mtcars, file = file, row.names = FALSE)
doc_attach_create(x, dbname="drinksdb", docid="asoda",
  attachment=file, attname="mtcarstable.csv")

## create a binary (png) attachment
file <- tempfile(fileext = ".png")
png(file)
plot(1:10)
dev.off()
doc_attach_create(x, dbname="drinksdb", docid="asoda",
  attachment=file, attname="img.png")

## create a binary (pdf) attachment
file <- tempfile(fileext = ".pdf")
pdf(file)
plot(1:10)
dev.off()
doc_attach_create(x, dbname="drinksdb", docid="asoda",
  attachment=file, attname="plot.pdf")

# get info for an attachment (HEAD request)
doc_attach_info(x, "drinksdb", docid="asoda", attname="mtcarstable.csv")
doc_attach_info(x, "drinksdb", docid="asoda", attname="img.png")
doc_attach_info(x, "drinksdb", docid="asoda", attname="plot.pdf")

# get an attachment (GET request)
res <- doc_attach_get(x, "drinksdb", docid="asoda",
  attname="mtcarstable.csv", type = "text")
read.csv(text = res)
doc_attach_get(x, "drinksdb", docid="asoda", attname="img.png")
doc_attach_get(x, "drinksdb", docid="asoda", attname="plot.pdf")

# delete an attachment
doc_attach_delete(x, "drinksdb", docid="asoda", attname="mtcarstable.csv")
doc_attach_delete(x, "drinksdb", docid="asoda", attname="img.png")
doc_attach_delete(x, "drinksdb", docid="asoda", attname="plot.pdf")

## End(Not run)