diff --git a/DESCRIPTION b/DESCRIPTION index 2f94c807..0848e656 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,7 @@ BugReports: https://github.com/r-lib/httr/issues Depends: R (>= 3.5) Imports: - curl (>= 3.0.0), + curl (>= 5.0.2), jsonlite, mime, openssl (>= 0.8), diff --git a/NEWS.md b/NEWS.md index 32b59973..4180465c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # httr 1.4.7 +* Add support for seeking in uploads (#741). + * Suppress another use of httpbin. * More aggressively skip httpbin using tests. diff --git a/R/body.R b/R/body.R index f2499b5a..dd4d3ede 100644 --- a/R/body.R +++ b/R/body.R @@ -25,6 +25,12 @@ body_config <- function(body = NULL, } bin }, + seekfunction = function(offset, ...) { + if (is.null(con)) { + con <<- file(body$path, "rb") + } + seek(con, where = offset) + }, postfieldsize_large = size ), content_type(body$type) diff --git a/tests/testthat/test-upload-file.R b/tests/testthat/test-upload-file.R new file mode 100644 index 00000000..588ee548 --- /dev/null +++ b/tests/testthat/test-upload-file.R @@ -0,0 +1,17 @@ +test_that("can upload with redirect", { + skip_on_cran() + + str <- paste(letters, collapse = '') + tmp <- tempfile() + writeBin(str, tmp) + + resp <- PUT( + "https://hb.cran.dev/redirect-to?url=/put&status_code=307", + body = upload_file(tmp) + ) + + expect_equal(resp$status_code, 200) + expect_equal(resp$url, "https://hb.cran.dev/put") + json <- content(resp) + expect_equal(json$data, str) +})