【发布时间】:2021-06-02 17:45:24
【问题描述】:
我有一个位置为“data/images/”的子目录,我需要我的 API 服务将图像上传到该子目录。我在这里使用 R 和 Plumber。我了解基本设置,但我似乎无法让我的代码将我上传的文件传送到我的目录中。
这是我的尝试:
图书馆(水管工) 图书馆(车)
#* Upload file
#* @param req:[file]
#* @post /uploadfile
function(req, res){
names(req)
print(names(req))
fileInfo <- list(formContents = Rook::Multipart$parse(req))
print(fileInfo)
## 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(paste0("data/images/",req, sepp=''))
file.copy(tmpfile, fn)
print(fn)
## Send a message with the location of the file
res$body <- paste0("Your file is now stored in ", fn, "\n")
res
}
任何帮助将不胜感激。
【问题讨论】:
-
print(fn)上打印什么?在list.files(fn)上? -
我认为代码不会到达那里。当我尝试上传文件时出现此错误: