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.
This is the API code
#* @post /test/1
function(req, res){
fileInfo <- list(formContents = Rook::Multipart$parse(req))
rdstmpfile <- fileInfo$formContents$rds$tempfile
rds_file <- file.path("We_Got_RDS.rds")
file.copy(rdstempfile, rds_file)
}
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.