如何在API中使用Plumber将多个图像上载到子目录?
我有一个子目录,它的位置是“data/images/”,我需要我的API服务将图像上传到该子目录中。我用的是水管工和水管工。我了解基本设置,但我似乎无法让我的代码将上载的文件传送到我的目录中 这是我的尝试: 图书馆(水管工) 图书馆(Rook)如何在API中使用Plumber将多个图像上载到子目录?,r,image,api,plumber,R,Image,Api,Plumber,我有一个子目录,它的位置是“data/images/”,我需要我的API服务将图像上传到该子目录中。我用的是水管工和水管工。我了解基本设置,但我似乎无法让我的代码将上载的文件传送到我的目录中 这是我的尝试: 图书馆(水管工) 图书馆(Rook) #*上传文件 #*@param req:[文件] #*@post/uploadfile 功能(req、res){ 名称(req) 打印(姓名(要求)) fileInfo因此,在一堆头发拉扯之后,这基本上就是允许您将图片上载到指定子目录的代码。此代码需要管
#*上传文件
#*@param req:[文件]
#*@post/uploadfile
功能(req、res){
名称(req)
打印(姓名(要求))
fileInfo因此,在一堆头发拉扯之后,这基本上就是允许您将图片上载到指定子目录的代码。此代码需要管道工和Rook软件包才能工作:
library(plumber)
library(Rook)
#* @param req:[file]
#* @post /upload_test27
function(req, res) {
# Required for multiple file uploads
names(req)
# Parses into a Rook multipart file type;needed for API conversions
fileInfo <- list(formContents = Rook::Multipart$parse(req))
# This is where the file name is stored
# print(fileInfo$formContents$req$filename)
file_name <- fileInfo$formContents$req$filename
# The file is downloaded in a temporary folder
tmpfile <- fileInfo$formContents$req$tempfile
# Create a file path
fn <- (paste0("data/images/",file_name, sepp=''))
#Copies the file into the designated folder
file.copy(tmpfile, fn)
res$body <- paste0("Your file is now stored in ", fn, "\n")
res
}
图书馆(水管工)
图书馆(Rook)
#*@param req:[文件]
#*@post/upload_test27
功能(req、res){
#需要进行多个文件上载
名称(req)
#解析为Rook多部分文件类型;API转换需要
fileInfo它在print(fn)
和list.files(fn)
上打印什么?我认为代码不会到达那里。我在尝试上载文件时遇到此错误:
library(plumber)
library(Rook)
#* @param req:[file]
#* @post /upload_test27
function(req, res) {
# Required for multiple file uploads
names(req)
# Parses into a Rook multipart file type;needed for API conversions
fileInfo <- list(formContents = Rook::Multipart$parse(req))
# This is where the file name is stored
# print(fileInfo$formContents$req$filename)
file_name <- fileInfo$formContents$req$filename
# The file is downloaded in a temporary folder
tmpfile <- fileInfo$formContents$req$tempfile
# Create a file path
fn <- (paste0("data/images/",file_name, sepp=''))
#Copies the file into the designated folder
file.copy(tmpfile, fn)
res$body <- paste0("Your file is now stored in ", fn, "\n")
res
}