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)
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.