我正在使用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以获取有关如何更有效地上传文件的信息。