You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Google Drive API的PUT命令更新文件时遭遇404错误求助

解决Google Drive API PUT更新文件返回404的问题
  • 核心问题:你用PUT方法搭配multipart上传类型是不匹配的。Google Drive的multipart上传更新需要用POST方法,再通过请求头指定覆盖为PUT语义。
  • 修正后的curl命令:
    curl -v -X POST -L \
      -H "Authorization: Bearer <accessToken>" \
      -H "X-HTTP-Method-Override: PUT" \
      -F 'file=@<filePath>;type=application/octet-stream' \
      "https://www.googleapis.com/upload/drive/v3/files/<fileId>?uploadType=multipart"
    
  • 额外排查项:
    • 确认accessToken权限:必须包含https://www.googleapis.com/auth/drive或https://www.googleapis.com/auth/drive.file权限范围,且token未过期。
    • 验证文件ID有效性:可以用curl -H "Authorization: Bearer <accessToken>" "https://www.googleapis.com/drive/v3/files/<fileId>"请求,确认文件是否存在。
    • 检查URL正确性:确保fileId没有输入错误,URL中无多余空格或字符。

内容的提问来源于stack exchange,提问作者Sourav Suman

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 19:36:17