Get file through API call (R & plumber)

二次信任 提交于 2019-12-01 20:43:33

问题


I'm using plumber as a simple web-api service for some R functions.

I would like to provide a file 'download' (on the client side) through an R function very much like flask is doing it in python through send_file and send_from_directory.

I tried

#* @get /datafile
get_file <- function(){
  return(file('path-to-file.RData'))
}

But unfortunately it didn't work (because the return value cannot be transformed to JSON). I'm aware of static file server option in plubmer, but I really want to provide only one single file and not a directory. (Although serving files in directory through @assets seems to be a more secure option.)


回答1:


Sorry this isn't better documented, but see some examples here: https://github.com/trestletech/plumber/blob/master/tests/testthat/files/includes.R

I don't remember if I've tested with binary data or how it will handle the Rdata content type, so if things are still weird please open a ticket.



来源:https://stackoverflow.com/questions/44185675/get-file-through-api-call-r-plumber

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!