通过API调用获取文件(R& plumber) [英] Get file through API call (R & plumber)
问题描述
我将水管工用作一些R函数的简单Web API服务.
I'm using plumber as a simple web-api service for some R functions.
我想通过R函数(类似于烧瓶是通过send_file和send_from_directory 在python中完成的.
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.
我尝试过
#* @get /datafile
get_file <- function(){
return(file('path-to-file.RData'))
}
但是不幸的是,它没有用(因为返回值不能转换为JSON).我知道plubmer中的静态文件服务器选项,但我真的只想提供一个单个文件而不是目录. (尽管通过@assets
在目录中提供文件似乎是一个更安全的选择.)
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.)
推荐答案
Sorry this isn't better documented, but see some examples here: https://github.com/trestletech/plumber/blob/master/tests/testthat/files/includes.R
我不记得我是否已经对二进制数据进行过测试,或者它如何处理Rdata内容类型,所以如果情况仍然很怪异请打开票证.
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.
这篇关于通过API调用获取文件(R& plumber)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!