0

I would like to receive an XLSX file in a Plumber endpoint. After seeing the following posts about it, the next code is what I ended up doing:

sender:

library(httr)

POST(paste0(Sys.getenv('SERVER_HOST'), '/', Sys.getenv('SERVER_ENDPOINT')),
    body = list(f = upload_file(file.path('test.xlsx'))))

server:

library(readxl)
library(jsonlite)

#* @param /f:[file]
#* @post /data
function(f) {
  filename <- 'read.xlsx'
  conn <- file(filename, 'wb')
  content <- Reduce(function(acc, cur) paste0(acc, cur), f[1])
  decoded <- base64_dec(f[[1]])
  writeBin(decoded, con = conn)
  close(conn)
  print(read_excel(filename))
}

But the saved downloaded read.xslx file is different than test.xlsx. Can anyone, please, help me?

1 Answers1

0

I ended up changing the server:

library(readxl)
library(jsonlite)
library(readr)

#* @post /data
function(req, res) {
  filename <- 'read.xlsx'
  content <- req$body$f$value
  write_file(content, filename)
  print(read_excel(filename))
}

To work properly