【发布时间】: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