Permalink
Browse files

0.2.5

  • Loading branch information...
1 parent e33c79f commit 716f347e0a48e899b1fe7b7c1896ad53a21cd95a @wactbprot committed Sep 6, 2013
View
@@ -1,14 +1,14 @@
Package: R4CouchDB
Type: Package
Title: A R convenience layer for CouchDB
-Version: 0.2.3
-Date: 2013/06/22
+Version: 0.2.5
+Date: 2013/09/05
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 returns a list() containing the
- connection setup . Such a list can be generated by cdbIni().
+ connection setup. Such a list can be generated by cdbIni().
License: BSD
LazyLoad: yes
Depends:
@@ -2,9 +2,9 @@
#'
#' 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}.
+#' The function uses \code{guessMIMEType()} to do exactly this.
+#' If the switch \code{cdb$attachmentsWithPath} is set to \code{TRUE}
+#' the attachments were saved with path.
#'
#' @usage cdbAddAttachment(cdb)
#' @param cdb The list \code{cdb} has to contain
@@ -17,42 +17,43 @@
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())
-
- 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,
- "/",
- 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)
- }
+ 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())
+
+ close(con)
+
+ if(cdb$attachmentsWithPath){
+ fbn <- cdb$fileName
+ }else{
+ fbn <- basename(cdb$fileName)
+ }
+ ctp <- toString(guessMIMEType(basename(fbn)))
+ 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)
+ }
}
Oops, something went wrong.

0 comments on commit 716f347

Please sign in to comment.