python 文件分块上传

# chunk_size 每块的大小
def read_in_chunks(file_object, chunk_size=1048576):
    while True:
        data = file_object.read(chunk_size)
        if not data:
            break
        yield data

file_path = './temp.mp3'
f = open(file_path, 'rb+')
index = 1
for chunk in read_in_chunks(f):
    # index 块数
    # chunk 块
    # 上传逻辑
    # upload_block(index, chunk)
    index += 1
f.close()

本文为作者刘明野发布,未经允许禁止转载!
5691
0
29
发表留言

友情链接