diff --git a/DESCRIPTION b/DESCRIPTION index 26fe812d..1ddd209d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: orderly2 Title: Orderly Next Generation -Version: 1.99.32 +Version: 1.99.33 Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"), email = "rich.fitzjohn@gmail.com"), person("Robert", "Ashton", role = "aut"), diff --git a/R/location_http.R b/R/location_http.R index 66205a03..47e84f3d 100644 --- a/R/location_http.R +++ b/R/location_http.R @@ -70,9 +70,16 @@ orderly_location_http <- R6::R6Class( }, push_file = function(src, hash) { + size <- file.info(src)$size + con <- file(src, "rb") + withr::defer(close(con)) + res <- private$client$request( sprintf("/file/%s", hash), - function(r) httr2::req_body_file(r, src, "application/octet-stream")) + function(r) { + http_body_connection(r, con, size, "application/octet-stream") + }) + invisible(NULL) }, diff --git a/R/outpack_http_client.R b/R/outpack_http_client.R index 94a33c55..6954f8b5 100644 --- a/R/outpack_http_client.R +++ b/R/outpack_http_client.R @@ -33,6 +33,22 @@ outpack_http_client <- R6::R6Class( } )) + +#' Attach a connection as the request's body. +#' +#' It is the caller's responsibility to keep the connection open for the +#' duration of the request and to close it afterwards. +http_body_connection <- function(request, con, size, type) { + request <- httr2::req_headers(request, "Content-Type" = type) + request <- httr2::req_options( + request, + post = TRUE, + readfunction = function(nbytes, ...) readBin(con, "raw", nbytes), + seekfunction = function(offset, ...) seed(con, offset), + postfieldsize_large = size + ) +} + http_client_request <- function(url, customize = identity, download = NULL, parse_json = TRUE) { req <- httr2::request(url)