我正在尝试使用 R Plumber 通过 HTTP post 请求访问 PDF,使用 tabulizer 包读取它,并使用 JSON 格式的 PDF 进行响应。我通过 Postman 将 53kb PDF 发布到我的路线并收到错误:
Error in normalizePath(path.expand(path), winslash, mustWork).
我的 R API 路由代码如下:
#' @post /tab
#' @json
function(req){
library("tabulizer")
f <- req$postBody
extract_tables(f)
}
当我将 extract_tables() 函数与我正在使用的 PDF 的本地路径一起使用时,它可以完美地作为获取路由。
#' @get /tab
#' @json
function(){
library("tabulizer")
f <- "C:/Users/kelse/Desktop/Rscripts/Tessaract/table.pdf"
extract_tables(f)
}
有人知道如何通过 Plumber 发布 pdf 文件并在函数中访问它吗?
最佳答案
您可以尝试使用@序列化器通过HTTP发布
#* @serializer contentType list(type="application/pdf")
#* @get /pdf
function(){
tmp <- tempfile()
pdf(tmp)
plot(1:10, type="b")
text(4, 8, "PDF from plumber!")
text(6, 2, paste("The time is", Sys.time()))
dev.off()
readBin(tmp, "raw", n=file.info(tmp)$size)
}
关于R Plumber 发布 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52786869/