0

I am currently using the httr package to download an excel file in R.

res <- httr::POST(url = 'https:URL', 
             httr::add_headers(.headers=headers), 
             httr::set_cookies(.cookies = cookies), 
             body = payload)

test <- content(res, as = "raw")

the result is a 13.7 MB large raw:

 str(test)
 raw [1:13714912] 50 4b 03 04 ...

If I try to parse the contents, it recognizes the mime type for an excel document:

test <- content(res, as = "parse")
Error: No automatic parser available for application/vnd.ms-excel.

The size is correct for the file I am trying to work with

I cannot figure out how to read the data of the raw format of the excel file. All of the methods I can find require a path to import excel files. I would appreciate any assistance that could be provided.

CapnBody
  • 1
  • 1
  • Have you looked at [Download a xls file from url into a dataframe (Rcurl)?](https://stackoverflow.com/q/19600926/4752675) ? – G5W Sep 13 '21 at 22:10
  • 1
    @G5W thank you for the response. I was able to work around the problem by adding write_disk(Path, overwrite = TRUE) to the POST call, and it allowed me to write the file to disk. I was then able to read_xlsx. It added a step as opposed to reading the xlsx file directly from memory, but solved my problem. – CapnBody Sep 22 '21 at 17:47

0 Answers0