Closed 2shou closed 8 years ago
:smile: 把MP4文件分成一堆块,每传一块记录一下返回的MD5,然后释放块占用的内存。最后调用合并文件就好了呗
#coding: utf-8
import os,json,sys,tempfile
from baidupcsapi import PCS
pcs = PCS('username','password')
chinksize = 1024*1024*16
fid = 1
md5list = []
tmpdir = tempfile.mkdtemp('bdpcs')
with open(sys.argv[1],'rb') as infile:
while 1:
data = infile.read(chinksize)
if len(data) == 0: break
smallfile = os.path.join(tmpdir, 'tmp%d' %fid)
with open(smallfile, 'wb') as f:
f.write(data)
print('chunk%d size %d' %(fid, len(data)))
fid += 1
print('start uploading...')
ret = pcs.upload_tmpfile(open(smallfile, 'rb'))
md5list.append(json.loads(ret.content)['md5'])
print('md5: %s' %(md5list[-1]))
os.remove(smallfile)
os.rmdir(tmpdir)
ret = pcs.upload_superfile('/'+os.path.basename(sys.argv[1]), md5list)
print ret.content
写了个简单的,不嫌丑可以拿着先用。python upload.py huge_file
@ly0
@2shou 已更新到README fix in #33
求完善这个demo,云主机内存有限,稍微大一点的文件就报
MemoryError
了。 希望上传的是一个mp4
文件,不是按行分隔的文本文件。