【问题标题】:Upload multiple file through plumber API in R通过 R 中的管道工 API 上传多个文件
【发布时间】:2021-05-18 07:19:42
【问题描述】:

我正在使用 R 中的 Plumber 开发 REST API。在其中我有一个模块,我支持上传多个 CEL 文件并运行算法,获取输出并将其显示在前端。

我参考了这段代码,但我很困惑这段代码是否正确。

plumber_api.R

    library(plumber)
    library(Rook)
    
    #* Upload file
    #* @param upload File to upload
    #* @post /uploadfile
    function(req, res){
      fileInfo <- list(formContents = Rook::Multipart$parse(req))
      ## The file is downloaded in a temporary folder
      tmpfile <- fileInfo$formContents$upload$tempfile
      ## Copy the file to a new folder, with its original name
      fn <- file.path('~/Downloads', fileInfo$formContents$upload$filename)
      file.copy(tmpfile, fn)
      ## Send a message with the location of the file
      res$body <- paste0("Your file is now stored in ", fn, "\n")
      res
    }

start_plumber_api.R

plumber::plumb("C:/wamp64/www/testing/upload.R")$run(port = 1234)

HTML

<form action="http://127.0.0.1:1234/uploadfile" method="POST" enctype="multipart/form-data">
    <label>Upload CEL File</label><br>
    <input type="file" id="files" accept=".CEL, .gz" multiple />
    <input type="submit" value="upload">
  </form>

收到此错误

Warning in Rook::Multipart$parse(req) : bad content body

谁能告诉我这个代码上传CEL文件是否正确,还有谁能解释一下错误是什么意思??????

请帮忙!

提前致谢

【问题讨论】:

    标签: r api file-upload upload plumber


    【解决方案1】:

    如果有人像我一样面临同样的问题。

    你可以参考这个 Github 链接:-

    https://github.com/rstudio/plumber/issues/579

    #* @param f:[file]
    #* @post /upload
    function(f) {
      names(f)
    }
    

    此功能可让您一次上传多个文件,无论它可能是任何文件,并且在上传文件之前,您必须限制要上传的文件作为输入。

    【讨论】:

      猜你喜欢
      • 2015-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-21
      相关资源
      最近更新 更多