Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add wrapper for fileUpload

  • Loading branch information...
commit 7f427d54255e0d62a799af5928d77e154db97754 1 parent 657a33d
@hadley hadley authored
View
1  DESCRIPTION
@@ -54,3 +54,4 @@ Collate:
'url-query.r'
'http-patch.r'
'user-agent.r'
+ 'upload-file.r'
View
1  NAMESPACE
@@ -29,6 +29,7 @@ export(set_cookies)
export(stop_for_status)
export(text_content)
export(timeout)
+export(upload_file)
export(use_proxy)
export(user_agent)
export(verbose)
View
6 R/http-post.r
@@ -17,14 +17,12 @@
#' POST(b)
#' POST(b, body = "A simple text string")
#' POST(b, body = list(a = 1, b = 2, c = 3))
-#'
-#' library(RCurl)
-#' POST(b, body = list(a = 1, file = fileUpload(system.file("CITATION"))))
+#' POST(b, body = list(a = 1, file = upload_file(system.file("CITATION"))))
#'
#' b2 <- "http://httpbin.org/post"
#' POST(b2, body = "A simple text string")
#' POST(b2, body = list(x = "A simple text string"))
-#' POST(b2, body = list(y = fileUpload(system.file("CITATION"))))
+#' POST(b2, body = list(y = upload_file(system.file("CITATION"))))
POST <- function(url = NULL, config = list(), body = NULL, multipart = TRUE, ..., handle = NULL) {
hu <- handle_url(handle, url, ...)
make_request("post", hu$handle, hu$url, body = body,
View
3  R/http-put.r
@@ -12,8 +12,7 @@
#' b2 <- "http://httpbin.org/put"
#' PUT(b2, body = "A simple text string")
#' PUT(b2, body = list(x = "A simple text string"))
-#' library(RCurl)
-#' PUT(b2, body = list(y = fileUpload(system.file("CITATION"))))
+#' PUT(b2, body = list(y = upload_file(system.file("CITATION"))))
PUT <- function(url = NULL, config = list(), body = NULL, multipart = TRUE, ..., handle = NULL) {
hu <- handle_url(handle, url, ...)
make_request("put", hu$handle, hu$url, body = body,
View
13 R/upload-file.r
@@ -0,0 +1,13 @@
+#' Upload a file with \code{\link{POST}} or \code{\link{PUT}}.
+#'
+#' This is a tiny wrapper for \pkg{RCurl}'s \code{\link[RCurl]{fileUpload}}.
+#'
+#' @param x path to file
+#' @export
+#' @examples
+#' POST("http://httpbin.org/post",
+#' body = list(y = upload_file(system.file("CITATION"))))
+upload_file <- function(path) {
+ stopifnot(is.character(path), length(path) == 1)
+ fileUpload(path)
+}
View
2  inst/tests/test-PUT-POST.r
@@ -7,7 +7,7 @@ round_trip <- function(method, body = NULL, ...) {
}
methods <- c("POST", "PUT")
-citation <- fileUpload(system.file("CITATION"))
+citation <- upload_file(system.file("CITATION"))
citation_val <- c(readLines(system.file("CITATION")), "")
test_that("empty body gives empty data element", {
View
6 man/POST.Rd
@@ -49,13 +49,11 @@ b <- new_bin()
POST(b)
POST(b, body = "A simple text string")
POST(b, body = list(a = 1, b = 2, c = 3))
-
-library(RCurl)
-POST(b, body = list(a = 1, file = fileUpload(system.file("CITATION"))))
+POST(b, body = list(a = 1, file = upload_file(system.file("CITATION"))))
b2 <- "http://httpbin.org/post"
POST(b2, body = "A simple text string")
POST(b2, body = list(x = "A simple text string"))
-POST(b2, body = list(y = fileUpload(system.file("CITATION"))))
+POST(b2, body = list(y = upload_file(system.file("CITATION"))))
}
View
3  man/PUT.Rd
@@ -54,7 +54,6 @@ PUT("http://httpbin.org/put")
b2 <- "http://httpbin.org/put"
PUT(b2, body = "A simple text string")
PUT(b2, body = list(x = "A simple text string"))
-library(RCurl)
-PUT(b2, body = list(y = fileUpload(system.file("CITATION"))))
+PUT(b2, body = list(y = upload_file(system.file("CITATION"))))
}
View
18 man/upload_file.Rd
@@ -0,0 +1,18 @@
+\name{upload_file}
+\alias{upload_file}
+\title{Upload a file with \code{\link{POST}} or \code{\link{PUT}}.}
+\usage{
+ upload_file(path)
+}
+\arguments{
+ \item{x}{path to file}
+}
+\description{
+ This is a tiny wrapper for \pkg{RCurl}'s
+ \code{\link[RCurl]{fileUpload}}.
+}
+\examples{
+POST("http://httpbin.org/post",
+ body = list(y = upload_file(system.file("CITATION"))))
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.