Permalink
Browse files

use guessmimetype to guess mime type (in cadAddAttachment)

	geändert:   R4CouchDB/DESCRIPTION
	geändert:   R4CouchDB/R/cdbAddAttachment.R
	gelöscht:    R4CouchDB_0.1.1.tar.gz
	gelöscht:    R4CouchDB_0.1.2.tar.gz
	neue Datei:   R4CouchDB_0.2.3.tar.gz
	gelöscht:    R4CouchDB_0.2.tar.gz
	geändert:   example/test-session.R
  • Loading branch information...
1 parent a83df66 commit c56cfde158788dbdc05dc8b75e9b850e3cab9584 @wactbprot committed Jun 22, 2013
View
8 R4CouchDB/DESCRIPTION
@@ -1,14 +1,14 @@
Package: R4CouchDB
Type: Package
Title: A R convenience layer for CouchDB
-Version: 0.2.2
-Date: 2013/06/06
+Version: 0.2.3
+Date: 2013/06/22
Author: wactbprot
Maintainer: <thsteinbock@web.de>
Description: The R4CouchDB package provides a collection of functions for
basic database and document management operations such as add and
- delete. Every cdbFunction() gets and emits a list containing the
- connection setup. Such a list can be generated by cdbIni().
+ delete. Every cdbFunction() gets and returns a list() containing the
+ connection setup . Such a list can be generated by cdbIni().
License: BSD
LazyLoad: yes
Depends:
View
60 R4CouchDB/R/cdbAddAttachment.R
@@ -1,53 +1,57 @@
#' Add attachments
-#'
+#'
#' This function adds attachments to a doc.
-#'
+#'
#' The function uses a simple call to \code{strsplit(fileName, ".")} and takes
#' the last entry of the resulting vector as the \code{Content-Type} in the
#' \code{httpheader}.
-#'
+#'
#' @usage cdbAddAttachment(cdb)
#' @param cdb The list \code{cdb} has to contain
#' \code{cdb$fileName},\code{cdb$serverName}, \code{cdb$DBName} and a
#' \code{cdb$id}.
#' @return \item{cdb}{The result is stored in \code{cdb$res} }
#' @author wactbprot
#' @keywords misc
-#'
+#'
cdbAddAttachment <- function( cdb){
fname <- deparse(match.call()[[1]])
cdb <- cdb$checkCdb(cdb,fname)
-
+
if(cdb$error == ""){
- tmpN <- length(tmpFn <- unlist(strsplit(cdb$fileName,"\\.")))
- noOfBytes <- file.info(cdb$fileName)$size
-
- con <- file(cdb$fileName, "rb")
- data <- readBin(con,n=noOfBytes,raw())
+ tmpN <- length(tmpFn <- unlist(strsplit(cdb$fileName,"\\.")))
+ noOfBytes <- file.info(cdb$fileName)$size
+
+ con <- file(cdb$fileName, "rb")
+ data <- readBin(con, n = noOfBytes,raw())
+
close(con)
+
+ fbn <- basename(cdb$fileName)
+ ctp <- toString(guessMIMEType(fbn))
- cdb$rev <- cdbGetDoc(cdb)$res$'_rev'
- adrString <- paste(cdb$baseUrl(cdb),
- cdb$DBName,"/",
- cdb$id,"/",
- basename(cdb$fileName),"?rev=",
- cdb$rev,
- sep="")
-
- res <- getURL(adrString,
- customrequest = "PUT",
- postfields = data,
- httpheader=c("Content-Type"=paste("image/",
- tmpFn[tmpN],
- sep="")),
- curl = cdb$curl,
- .opts = cdb$opts(cdb)
- )
+ cdb$rev <- cdbGetDoc(cdb)$res$'_rev'
+ adrString <- paste(cdb$baseUrl(cdb),
+ cdb$DBName,
+ "/",
+ cdb$id,
+ "/",
+ fbn,
+ "?rev=",
+ cdb$rev,
+ sep = "")
+
+ res <- getURL(adrString,
+ customrequest = "PUT",
+ postfields = data,
+ httpheader = c("Content-Type" = ctp))
+
+
return(cdb$checkRes(cdb,res))
-
+
}else{
stop(cdb$error)
}
View
BIN R4CouchDB_0.1.1.tar.gz
Binary file not shown.
View
BIN R4CouchDB_0.1.2.tar.gz
Binary file not shown.
View
BIN R4CouchDB_0.2.3.tar.gz
Binary file not shown.
View
BIN R4CouchDB_0.2.tar.gz
Binary file not shown.
View
42 example/test-session.R
@@ -1,12 +1,17 @@
#'
#' R4CouchDB example session
-#'
+#'
#' @author wactbprot
-#' load the R4Couchdb package
-#' by means of the source command
-#'
-srcPath <- "../R4CouchDB/R/"
-fn <- list.files(srcPath, pattern="R$")
+#'
+#' This code thinks you are in the
+#' example folder; if you are not execute:
+#' > setwd("path/to/example")
+#'
+#' load the R4CouchDB functions
+#' by means of the source command.
+#'
+srcPath <- "../R4CouchDB/R/"
+fn <- list.files(srcPath, pattern="R$")
for (k in 1:length(fn)){
source(paste(srcPath, fn[k], sep=""))
}
@@ -18,13 +23,13 @@ library(RJSONIO)
#' At first one have to generate the ini list.
#' This list (here ccc) contains everything
#' you need for the connection.
-ccc <- cdbIni()
-#' one can do some auth settings
+ccc <- cdbIni()
+#' one can do some auth settings
#' ccc$uname <- "user.name"
#' ccc$pwd <- "pass.word"
-#'
+#'
#' database list please
-ccc <- cdbListDB(ccc)
+ccc <- cdbListDB(ccc)
ccc$res
ccc$queryParam <- "count=10"
@@ -61,28 +66,25 @@ cdbGetDoc(ccc)$res
ccc$dataList$Date <- date()
ccc <- cdbUpdateDoc(ccc)
#'
-#' make a png (stolen from ?persp)
+#' make a 3d plot (stolen from ?persp)
x <- seq(-10, 10, length= 30)
y <- x
-f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
+f <- function(x,y) {r <- sqrt(x^2+y^2); 10 * sin(r)/r }
z <- outer(x, y, f)
#'
z[is.na(z)] <- 1
-op <- par(bg = "white")
-ccc$fileName <- paste("../",
- ccc$DBName,
- ".test.png",
- sep="")
+op <- par(bg = "black")
+ccc$fileName <- "3dplot.pdf"
-#' make an png
-png(filename = ccc$fileName)
+pdf(ccc$fileName)
persp(x, y, z,
theta = 30,
phi = 30,
expand = 0.5,
col = "lightblue")
dev.off()
-#' add the plot as attachment to the db
+#' add the plot as attachment to the database
+#' it workes over ccc$fileName
ccc <- cdbAddAttachment(ccc)
#' remove the db when ready

0 comments on commit c56cfde

Please sign in to comment.