用 Python 通过 api 用 post 上传文件怎么分块?
source link: https://www.v2ex.com/t/894722
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
很多网站上传东西都有提供 api 可以用 requests 这些库 with open 后发简单的 post 请求就能上传 但是对于小内存机子上传大文件就会爆内存 请问怎么做才能不全部读取到内存再上传
vopin 3 小时 26 分钟前 via iPhone 文件能有多大?大文件一般分段上传吧。
|
xiangyuecn 2 小时 49 分钟前
“会爆内存”,明显的 http 请求实现的问题,body 部分并没有哪里约束了必须一次性先生成一个完整的 body 才能发送请求。
稍微聪明那么一点的底层框架代码,都应该读一点发送一点,不存在内存问题(但实现代码会很复杂)。
大文件需要注意的就是失败如何重传的问题,只通过一个请求发送大文件,如果传到 99%的时候失败了,那都得从头再来。
-----
回到问题上,“通过 api 用 post 上传文件怎么分块”,本质上跟 python 不 python 没有一毛钱关系,更多的是需要 api 提供分块上传支持,比如:单次请求可以上传 4MB 的数据块,每次请求发送文件中的指定位置大小的数据块,失败了就重传这 4MB 的数据,最后全部传完了,再调一个 api 通知合并文件。
Recommend
-
11
渗透技巧——通过cmd上传文件的N种方法 三好学生
-
27
今天刚好看到了一片文章分块上传的文章,自己并没有实现过。思来想去实践一下并且前后双端进行实现。文笔不好请多担待,不明白评论看到即回。俗话事吃水不忘挖井人,附上文章链接
-
26
引 Once upon a time,COVID-19席卷全球,Chinese Government要求学校复课时必须测量学生体温 YC中学有几万名同学,要找到发烧的同学进行隔离 如果要让一位老师完成所有测温任务,那这将是一个大工程,效率会很低(左...
-
17
在HTTP/1.0中, 响应头必须含有Content-Length; 在HTTP/1.1中引入chunk概念; 分块传输编码(Chunked transfer encoding)是超文本传输协议(HTTP)中的一种数据传输机制,允许HTTP由网页服务器发送给客户端应用( 通常是网页浏览器...
-
7
树上莫队和树上分块大力出奇迹 Ver.2In OI By Rapiz 2017-02-01 分块,
-
8
分块传输就不能跨域?`chunked` 编码影响 `CORS` 跨域的问题排查 (查看原文) 在日常开发中我们经常遇到需要进行跨域的情况,虽然跨域的方案有非常多,但是最推...
-
2
通过Web应用向IPFS上传文件 IPFS ...
-
3
为什么要将文件分块编码? Posted on 2014/01/06 ...
-
7
5 ipfs文件上传后,可以通过localhost访问,却不能通过ipfs网关访问。 ...
-
4
curl Curl POST JSON并上传文件 curl是用于在本地计算机与远程服务器之间传输数据的命令行工具 ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK