You need to enable JavaScript to run this app. 使用rapiclient Swagger API向Figshare上传本地文件的方法咨询
优惠活动
大模型
产品
解决方案
定价
更多

使用rapiclient Swagger API向Figshare上传本地文件的方法咨询

Figshare API 本地文件上传问题解答

关于“无需上传到Figshare的文件”的含义

该描述对应link参数的使用场景:如果你要关联的文件已经存放在其他公网可访问的存储服务中,只需传入该文件的公网URL,Figshare不会将文件本身存储到自身服务器,仅在你的仓库中添加指向该URL的跳转入口,不需要你上传文件内容。你之前报错400是因为link参数要求传入公网可访问的HTTP/HTTPS链接,不能填本地文件路径。

本地文件~/foo.txt的上传步骤

上传本地文件不需要传link参数,需按以下流程操作:

  1. 预处理本地文件,获取三个必填参数:文件MD5值、带后缀的文件名、文件大小(单位为字节)
  2. 调用private_article_upload_initiate传入上述三个参数,获取上传地址和生成的文件ID
  3. 将本地文件内容上传到返回的上传地址
  4. 调用private_article_upload_complete确认上传完成,将文件关联到你的仓库

完整示例代码

library(digest)

# 转换本地路径为绝对路径
local_file <- path.expand("~/foo.txt")

# 计算上传所需参数
file_md5 <- digest(local_file, algo = "md5", file = TRUE)
file_name <- basename(local_file)
file_size <- file.size(local_file)

# 1. 初始化上传任务
init_result <- fs_api$operations$private_article_upload_initiate(
  article_id = id,
  md5 = file_md5,
  name = file_name,
  size = file_size
)
upload_url <- init_result$upload_url
new_file_id <- init_result$id

# 2. 上传文件内容
upload_resp <- PUT(
  upload_url,
  body = upload_file(local_file),
  add_headers(header)
)
stop_for_status(upload_resp)

# 3. 确认上传完成
complete_result <- fs_api$operations$private_article_upload_complete(
  article_id = id,
  file_id = new_file_id
)
stop_for_status(complete_result)

注意事项

如果需要上传的文件大于100MB,Figshare要求分片上传,你需要按初始化接口返回的parts字段拆分文件,逐个上传分片后再调用确认接口。


内容的提问来源于stack exchange,提问作者Otto Kässi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.16 15:45:03