Загрузите zip-файл из хранилища BLOB-объектов Azure с помощью R

Я хочу загрузить zip-файл из хранилища Azure blob, но результат, который я получаю с помощью «azureBlobCall», не является zip-файлом. Я не знаю, как указать тип контента и как получить правильный формат в R.


person HANIEH    schedule 02.08.2017    source источник


Ответы (1)


Мне удалось легко загрузить любой файл с помощью этого кода

library(httr)
library(RCurl)
library(xml2)

account #Account Name
container #container name
key #primary key
file #file to be downloaded
filepath #foldername for results to be downloaded

DownloadFromAZureBlob<-function(account,container,key,file,filepath){

  verb="GET"

  url <- paste("https://",account,".blob.core.windows.net/",container,'/',basename(file),sep="")

  container <- paste(container,'/',basename(file),sep = "")

  # combine timestamp and version headers with any input headers, order and create the CanonicalizedHeaders
  `x-ms-date` <- format(Sys.time(),"%a, %d %b %Y %H:%M:%S %Z", tz="GMT")
  headers <- setNames(c(`x-ms-date`, "2015-04-05"), 
                      c("x-ms-date", "x-ms-version"))
  headers <- headers[order(names(headers))]

  CanonicalizedHeaders <- paste(names(headers), headers, sep=":", collapse = "\n")

  CanonicalizedResource <- paste0("/",account,"/",container)

  # create the authorizationtoken
  signaturestring <- paste0(verb, "\n\n\n\n\n\n\n\n\n\n\n\n", CanonicalizedHeaders, "\n", CanonicalizedResource)
  requestspecificencodedkey <- RCurl::base64(
    digest::hmac(key=RCurl::base64Decode(key, mode="raw"),
                 object=enc2utf8(signaturestring),
                 algo= "sha256", raw=TRUE)
  )

  authorizationtoken <- paste0("SharedKey ", account, ":", requestspecificencodedkey)
  # make the call
  headers_final <- add_headers(Authorization=authorizationtoken, headers)
  #download to subdirectry "filepath"
  download.file(url,destfile=file.path(filepath, basename(file)), method='auto',extra =headers_final )


}

DownloadFromAZureBlob(account,container,key,file,filepath)
person HANIEH    schedule 02.08.2017