我正在使用 Dropbox API 将大量文件从一个 Dropbox 帐户迁移到另一个帐户。每个文件似乎需要 2 到 7 秒的时间。有什么方法可以加快使用 Dropbox API 移动文件的速度吗?
source = dropbox.Dropbox('connectionstring')
target = dropbox.Dropbox('connectionstring')
list_folder = source.files_list_folder('')
while list_folder:
files = re.findall(r'name=[\'"]?([^\'" >]+)', str(list_folder))
for f in files:
source.files_download_to_file(f,'')
files = open(f,mode='rb')
target.files_upload(files.read(),'')
files.close()
os.remove(f)
list_folder = source.files_list_folder_continue(list_folder.cursor)
最佳答案
是的,您可以使用“复制引用”直接在帐户之间复制文件或文件夹,而无需下载和重新上传文件。这些字符串用于标识一个帐户中的内容,可用于将该内容复制到另一个帐户。
要从源帐户获取文件或文件夹的复制引用,请使用/2/files/copy_reference/get:
https://www.dropbox.com/developers/documentation/http/documentation#files-copy_reference-get
要使用这些复制引用来保存目标帐户中的文件或文件夹,请使用/2/files/copy_reference/save:
https://www.dropbox.com/developers/documentation/http/documentation#files-copy_reference-save
或者,如果您由于某种原因无法使用复制引用,请务必查看 the Data Ingress Guide有关如何更有效地上传文件的信息。
关于python - 通过 dropbox APi 进行文件迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51069637/