Error connecting to azure blob storage API from R

后端 未结 3 1899
长情又很酷
长情又很酷 2020-12-17 02:44

I am attempting to work with Azure storage via the REST API in R. I\'m using the package httr which overlays Curl.

Setup

You can use R-fiddle: http://www.r

3条回答
  •  心在旅途
    2020-12-17 03:11

    Looks like your problem is with the key. The string of the key you have provided is actually base64 encoded. You need to decode that to the raw vector before you use it to sign the request. For example:

    url<-"https://preconstuff.blob.core.windows.net/pings?restype=container&comp=list"
    sak<-"Q8HvUVJLBJK+wkrIEG6LlsfFo19iDjneTwJxX/KXSnUCtTjgyyhYnH/5azeqa1bluGD94EcPcSRyBy2W2A/fHQ=="
    
    requestdate<-format(Sys.time(),"%a, %d %b %Y %H:%M:%S %Z", tz="GMT")
    signaturestring<-paste0("GET",paste(rep("\n",12),collapse=""),
    "x-ms-date:",requestdate,"
    x-ms-version:2009-09-19
    /preconstuff/pings
    comp:list
    restype:container")
    
    headerstuff<-add_headers(Authorization=paste0("SharedKey preconstuff:",
                             RCurl::base64(digest::hmac(key=RCurl::base64Decode(sak, mode="raw"),
                             object=enc2utf8(signaturestring),
                             algo= "sha256", raw=TRUE))),
                        `x-ms-date`=requestdate,
                        `x-ms-version`= "2009-09-19")
    
    content(GET(url,config = headerstuff, verbose() ))
    

    There are no more authentication errors this way, though no blobs are listed. Perhaps that's a different issue.

    Also, I changed the way the date/time was created to more "safely" change the local time to GMT.

提交回复
热议问题