通过 R 中的管道工 API 上传多个文件 [英] Upload multiple file through plumber API in R

查看:21
本文介绍了通过 R 中的管道工 API 上传多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am Developing REST API using Plumber in R. In which I have a module where I was support to upload multiple CEL file and runs the algorithms, get the output and show it in the front-end.

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

I had refer this code but I am confused Is this code is correct or not.

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文件,还有谁能解释一下错误是什么意思?????????

Can anyone tell me Is this code is correct to upload CEL file or not and also Can anyone please explain me what does the error what does it indicates???????

请帮忙!

提前致谢

推荐答案

如果有人和我一样面临同样的问题.

If anyone faces with the same issue like me.

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

You can refer this Github link:-

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

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

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

这篇关于通过 R 中的管道工 API 上传多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆