通过保管箱迁移文件 APi

File migration via dropbox APi

我正在使用保管箱 API 将大量文件从一个保管箱帐户迁移到另一个。每个文件似乎需要 2 到 7 秒。有什么方法可以加快使用保管箱移动文件所需的时间 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)

是的,您可以使用 "copy references" 直接在帐户之间复制文件或文件夹,无需下载和重新上传文件。这些是标识一个帐户中内容的字符串,可用于将该内容复制到另一个帐户。

要从源帐户获取对文件或文件夹的复制引用,请使用 /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 以获取有关如何更高效地上传文件的信息。