From 63b75a928fe149192b678969c89e4cb16a136d70 Mon Sep 17 00:00:00 2001 From: hong-revo Date: Fri, 3 Aug 2018 21:19:30 +1000 Subject: [PATCH] blob uploading from text connection --- R/blob_client_funcs.R | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/R/blob_client_funcs.R b/R/blob_client_funcs.R index e3f053d..48accdb 100644 --- a/R/blob_client_funcs.R +++ b/R/blob_client_funcs.R @@ -228,24 +228,28 @@ upload_blob <- function(container, src, dest, type="BlockBlob", blocksize=2^24, if(!is.null(lease)) headers[["x-ms-lease-id"]] <- as.character(lease) - # upload each block - remaining <- file.info(src)$size - blocklist <- list() - con <- file(src, open="rb") + con <- if(inherits(src, "textConnection")) + rawConnection(charToRaw(paste0(readLines(src), collapse="\n"))) + else file(src, open="rb") on.exit(close(con)) + + # upload each block + blocklist <- list() i <- 1 - while(remaining > 0) + while(1) { body <- readBin(con, "raw", blocksize) thisblock <- length(body) + if(thisblock == 0) + break + headers[["content-length"]] <- thisblock - id <- openssl::base64_encode(sprintf("%010d", i)) + id <- openssl::base64_encode(sprintf("%s-%010d", dest, i)) opts <- list(comp="block", blockid=id) do_container_op(container, dest, headers=headers, body=body, options=opts, http_verb="PUT") blocklist <- c(blocklist, list(Latest=list(id))) - remaining <- remaining - thisblock i <- i + 1 }