等峰也等你

博客园 首页 新随笔 联系 订阅 管理
  308 随笔 :: 0 文章 :: 0 评论 :: 15460 阅读

通过接口上传文件

 
proxiesproxies

proxiesproxies

文件上传接口场景

 

Since file-upload is a feature that will benefit many applications, this proposes an extension to HTML to allow information providers to express file upload requests uniformly, and a MIME compatible representation for file upload responses.

  • 1867 文档中说明文件上传是一种常见的需要求,但是使用 html 中的 form 表单格式却不支持,
  • 提出了一种兼容此需求的 mime type。
  • 解决接口测试流程中文件上传的问题
    • 指定 name
    • 指定 filename
    • 指定 content-type

使用 requests 如何上传

 
r = requests.post("https://httpbin.ceshiren.com/post",
files={"hogwarts_file": open("hogwarts.txt", "rb")})
# key值需要替换为文件名
# value 对应为文件二进制流
import requests
r = requests.post("https://httpbin.ceshiren.com/post",
files={"hogwarts_file": open("1.text", "rb")},
proxies = {"http": "http://127.0.0.1:8080",
"https": "http://127.0.0.1:8080"},
verify = False
)

文件分片上传

 
 

使用场景

 
  • 场景:上传一个大文件
  • 案例: 飞书,文件上传接口
  • 实现:将文件分片,然后发起多次请求,多次上传。
  • 使用接口:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/upload_prepare

实战过程

 
  1. 注册飞书
  2. 开通权限
  3. 分片上传

 

 

posted on   等峰也等你  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示