[英]Uploading Large Files to Dropbox using Dropbox API and Python Results in Error
I am trying to upload a large zipped file to Dropbox (about 2-3GB) using Python and the Dropbox API v2. 我正在尝试使用Python和Dropbox API v2将大型压缩文件上传到Dropbox(大约2-3GB)。 I am using the "chunked method" found here: dropbox API v2 upload large files using python .
我使用的是此处找到的“分块方法”: Dropbox API v2使用python上传大文件 。 Here is the code again for convenience:
再次为方便起见,下面是代码:
f = open(file_path)
file_size = os.path.getsize(file_path)
CHUNK_SIZE = 4 * 1024 * 1024
if file_size <= CHUNK_SIZE:
print dbx.files_upload(f, dest_path)
else:
upload_session_start_result = dbx.files_upload_session_start(f.read(CHUNK_SIZE))
cursor = dropbox.files.UploadSessionCursor(session_id=upload_session_start_result.session_id,
offset=f.tell())
commit = dropbox.files.CommitInfo(path=dest_path)
while f.tell() < file_size:
if ((file_size - f.tell()) <= CHUNK_SIZE):
print dbx.files_upload_session_finish(f.read(CHUNK_SIZE),
cursor,
commit)
else:
dbx.files_upload_session_append(f.read(CHUNK_SIZE),
cursor.session_id,
cursor.offset)
cursor.offset = f.tell()
However, when I run it I am getting a 但是,当我运行它时,
dropbox.exceptions.APIError
dropbox.exceptions.APIError
as well as 以及
UploadSessoionLookupError
UploadSessoionLookupError
and a 和一个
UploadSessionOffsetError
UploadSessionOffsetError
I think the error might be occurring at this line specifically: 我认为该错误可能专门在此行发生:
dbx.files_upload_session_append(f.read(CHUNK_SIZE),
cursor.session_id,
cursor.offset)
I've tried swapping that for 我试着换成
dbx.files_upload_session_append_v2(
f.read(self.CHUNK_SIZE), cursor)
but that didn't work either. 但这也不起作用。 Any suggestions?
有什么建议么?
On windows, be sure to open using binary mode 在Windows上,请确保使用二进制模式打开
f = open(file_path, 'rb')
f.read(chunk_size)
and f.tell()
were off. f.read(chunk_size)
和f.tell()
已关闭。
from python docs 来自python docs
On Windows,
tell()
can return illegal values (after anfgets()
) when reading files with Unix-style line-endings.在Windows上,当以Unix样式的行尾读取文件时,
tell()
可以返回非法值(在fgets()
)。 Use binary mode ('rb'
) to circumvent this problem.使用二进制模式(
'rb'
)可以解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.