I can't figure out how to implement a Plumber API, where the API will save a .rds file (it will get from the request) in it's working directory and do some data visualization steps and then finally return the result.
These .rds files are data files which is saved using saveRDS() method.
Client code (will use httr package to send the .rds file)
httr::content(POST('http://0.0.0.0:7000/test/1'),
body = list(
rds = upload_file("data.rds", mime::guess_type("data.rds"))
)
) -> res
What is the content-type of the .rds files ?
How to send the .rds file to plumber API ?
I tried to print fileInfo$formContents but I got NULL. Why I'm getting NULL ? It looks like it's not able to send the .rds file.
library(httr)
library(magrittr)
res <-
POST(
"http://0.0.0.0:7000/test/1",
body = list(
# send the file with mime type `"application/rds"` so the RDS parser is used
rds_file = upload_file("data.rds", "application/rds")
)
) %>%
content()
str(res)
#> List of 1
#> $ : logi TRUE
plumber.R code:
# Add a rds and multipart form parser
#' @parser rds
#' @parser multi
#' @post /test/1
function(req, res, rds_file) {
str(rds_file)
# now that you have the object, save it to a file
saveRDS(rds_file, "We_Got_RDS.rds")
TRUE # placeholder return value
}