Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
Mobistudios A.
10 years agoNew member | Level 1
Upload a directory including all its files and sub-directories
I’m trying to upload a directory to Dropbox along with all its contents
including any sub-directories and its contents using the Python API.
I can upload files OK and even create new Dropbox folders. I wonder if
anyone has a solution for this. Any help or code examples would be greatly
appreciated. Below the error message you can see the code.
The error message is as follows.
Traceback (most recent call last):
File "dir_2_dropbox.py", line 27, in <module>
response = client.put_file(dropbox_path, f)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/client.py", line 377, in put_file
return self.rest_client.PUT(url, file_obj, headers)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/rest.py", line 321, in PUT
return cls.IMPL.PUT(*n, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/rest.py", line 258, in PUT
return self.request("PUT", url, body=body, headers=headers, raw_response=raw_response)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/rest.py", line 227, in request
raise ErrorResponse(r, r.read())
Python code.
local_dir = ('/users/ninekay/desktop/scripts')
for root, dirs, files in os.walk(local_dir):
for filename in files:
local_path = os.path.join(root, filename)
relative_path = os.path.relpath(local_path, local_dir)
dropbox_path = os.path.join(‘/mobistudios’, relative_path)
with open(local_path, 'rb') as f:
client.put_file(dropbox_path, f)
1 Reply
Replies have been turned off for this discussion
- Greg-DB10 years ago
Dropbox Community Moderator
[Cross linking for reference: https://stackoverflow.com/questions/32034819/error-when-uploading-a-directory-to-dropbox-including-all-files-and-sub-director ]
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!