File migration via dropbox APi

≡放荡痞女 提交于 2019-12-08 07:02:35

问题


I'm using the dropbox API to migrate a large amount of files from one dropbox account to another. This seems to be taking between 2 and 7 seconds per file. Are there any ways to speed up the time it takes to move files using the 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)

回答1:


Yes, you can copy files or folders between accounts directly, without downloading and re-uploading the files, by using "copy references". These are strings that identify content in one account, and can be used to copy that content to another account.

To get copy references to files or folders from the source account, use /2/files/copy_reference/get:

https://www.dropbox.com/developers/documentation/http/documentation#files-copy_reference-get

To use those copy references to save the files or folders in the target account, use /2/files/copy_reference/save:

https://www.dropbox.com/developers/documentation/http/documentation#files-copy_reference-save

Alternatively, if you can't use copy references for some reason, be sure to check out the Data Ingress Guide for information on how to more efficiently upload files.



来源:https://stackoverflow.com/questions/51069637/file-migration-via-dropbox-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!