Dropbox Python API上载多个文件

2024-09-30 14:16:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用Dropbox Python SDK(v2)将一组pd.DataFrames作为CSV上传到Dropbox中的一个文件夹中。文件集不是特别大,但数量很多。使用批处理将有助于减少API调用并遵守documentation中概述的开发人员建议:

"The idea is to group concurrent file uploads into batches, where files in each batch are uploaded in parallel via multiple API requests to maximize throughput, but the whole batch is committed in a single, asynchronous API call to allow Dropbox to coordinate the acquisition and release of namespace locks for all files in the batch as efficiently as possible."

下面是SO中的几个答案(请参阅与我的问题最相关的here)和来自Dropbox论坛SDK维护人员的this答案,我尝试了以下代码:

commit_info = []
for df in list_pandas_df: 
    df_raw_str = df.to_csv(index=False)
    upload_session = dbx.upload_session_start(df_raw_str.encode())
    commit_info.append(
            dbx.files.CommitInfo(path=/path/to/db/folder.csv
    )

dbx.files_upload_finish_batch(commit_info)

尽管如此,在阅读files_upload_finish_batchdocstring时,我注意到该函数只接受一个CommitInfo列表作为参数(documentation),这是令人困惑的,因为非批处理版本(files_upload_session_finish)确实接受一个带有pathCommitInfo对象和一个包含会话数据的游标对象。在

我完全沉浸在文档中,即使是源代码也无法帮助理解批处理如何上载多个文件(而不是作为上载重文件的例子)。我错过了什么?在


Tags: 文件thetoininfoapidfsession

热门问题