使用R和REDCap API将文件导入文件存储库时出错

d7v8vwbk  于 2023-11-14  发布在  其他
关注(0)|答案(1)|浏览(107)

我正在使用redcap API尝试将文件上传到数据访问组内的文件存储库中:

library(RCurl)

#!/usr/bin/env Rscript
token <- "xyz123456"
url <- "https://redcap.myredcap/api/"
file <- '//example/my_directory/file_example.html'
formData <- list("token"=token,
                 action='import',
                 content='fileRepository',
                 folder_id=1,
                 returnFormat='json',
                 file=file
)
response <- httr::POST(url, body = formData, encode = "multipart")
result <- httr::content(response)
print(result)

字符串
获取此错误:

$error
[1] "No valid file was uploaded"


任何帮助赞赏!

m1m5dgzv

m1m5dgzv1#

尝试将file = file替换为file = httr::upload_file(file)-当我直接将文件上传到RC时,这对我很有效(尽管难以复制,但我只是在我的一个项目上测试了它,它工作了(虽然不是特定于DAG,但代码中唯一的区别是我没有folder_id = 1):

formData <- list(
  "token" = token,
  action = 'import',
  content = 'fileRepository',
  folder_id = 1,
  returnFormat = 'json',
  file = httr::upload_file(file)
)

字符串

相关问题