首页 > 解决方案 > 通过 R 管道工 api 上传文件不起作用

问题描述

我正在尝试使用管道工 api 上传 json 文件,但在 Postman 中进行测试时,我得到“405 - 方法不允许”。

使用的代码

# plumber.R

#* Echo the parameter that was sent in
#* @get /echo
function(){
  list(msg = 'Hello World')
}

#* Model
#* @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(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
}

使用以下 curl 命令上传文件

curl -v -F upload=@"D:\projects\notes1.txt" http://localhost:4535/uploadfile

邮递员错误

在此处输入图像描述

标签: rapipostmanplumber

解决方案


推荐阅读