1 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超13個(gè)贊
您可以使用plumber和Rook使用 POST 上傳文件。
這是一個(gè)小例子
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
}
運(yùn)行服務(wù)器
plumber::plumb('api.R')$run(port = 1234)
使用 curl 發(fā)送文件 test.txt
curl -v -F upload=@test.txt http://localhost:1234/uploadfile
添加回答
舉報(bào)