r - 通过 R 中的管道工 API 上传多个文件
问题描述
我正在REST API
使用R 中的 Plumber 进行开发。在其中我有一个模块,我支持上传多个 CEL 文件并运行算法,获取输出并将其显示在前端。
我参考了这段代码,但我很困惑这段代码是否正确。
管道工_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文件是否正确,还有谁能解释一下这个错误是什么意思??????
请帮忙!
先感谢您
解决方案
如果有人像我一样面临同样的问题。
你可以参考这个 Github 链接:-
https://github.com/rstudio/plumber/issues/579
#* @param f:[file]
#* @post /upload
function(f) {
names(f)
}
此功能将使您能够一次上传多个文件,无论它可能是任何文件,并且在上传文件之前,您必须限制要上传的文件作为输入。
推荐阅读
- mute - 无法在 wavesurfer.js 中静音一个频道
- python - 如何编写一个多线程函数来同时处理不同的任务?
- r - R:调用列表中的多个元素
- ios - 如何在 swift 4 中使用 json 对象发送 json 数据
- java - 如何将方法作为其他方法的参数传递,但使最后一个方法在其签名上具有泛型作为参数?
- aws-appsync - 嵌套 AppSync 架构中的选定更新
- android - fcm 使用 C# 将通知推送到带有主题消息的移动设备
- python - 从子进程运行两个不同的命令并捕获两个进程 Python 的输出
- javascript - 在leaflet.js 中的两个叠加层之间切换
- git - Git SSH 公钥身份验证在 Azure DevOps 上使用 git 失败