【问题标题】:R Plumber posting a PDFR 管道工发布 PDF
【发布时间】:2018-10-12 20:53:05
【问题描述】:

我正在尝试使用 R Plumber 通过 HTTP 发布请求访问 PDF,使用 tabulizer 包读取它,并使用 JSON 格式的 PDF 进行响应。我通过 Postman 将 53kb PDF 发布到我的路线并收到错误:

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 文件并在函数中访问它吗?

【问题讨论】:

  • 这是字面错误信息吗?冒号后面什么都没有?奇数...

标签: r plumber tabulizer


【解决方案1】:

您可以尝试使用@serializer 来通过 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)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多