0

I'm trying to upload a whole folder to dropbox but only the files get uploaded. Should I create a folder programatically or can I solve the folder-uploading so simple? Thanks

   import os
   import dropbox

   access_token = '***********************'

   dbx = dropbox.Dropbox(access_token)

   dropbox_destination = '/live'
   local_directory = 'C:/Users/xoxo/Desktop/man'

   for root, dirs, files in os.walk(local_directory):

       for filename in files:
           local_path = root + '/' + filename
           print("local_path", local_path)
           relative_path = os.path.relpath(local_path, local_directory)
           dropbox_path = dropbox_destination + '/' + relative_path

           # upload the file
           with open(local_path, 'rb') as f:
               dbx.files_upload(f.read(), dropbox_path)

error:

dropbox.exceptions.ApiError: ApiError('xxf84e5axxf86', UploadError('path', UploadWriteFailed(reason=WriteError('disallowed_name', None), upload_session_id='xxxxxxxxxxx')))

1 Answer 1

1

[Cross-linking for reference: https://www.dropboxforum.com/t5/API-support/UploadWriteFailed-reason-WriteError-disallowed-name-None/td-p/245765 ]

There are a few things to note here:

  • In your sample, you're only iterating over files, so you won't get dirs uploaded/created.
  • The /2/files/upload endpoint only accepts file uploads, not folders. If you want to create folders, use /2/files/create_folder_v2. You don't need to explicitly create folders for any parent folders in the path for files you upload via /2/files/upload though. Those will be automatically created with the upload.
  • Per the /2/files/upload documentation, disallowed_name means:

Dropbox will not save the file or folder because of its name.

So, it's likely you're getting this error because you're trying to upload an ignored filed, e.g., ".DS_STORE". You can find more information on those in this help article under "Ignored files".

5
  • thanks for your help. 2 things that are still not clear: 1, so I can't upload a folder containing files with only 1 command? 2, I have this code and no folder get created in dropbox: import dropbox; at="***"; dbx = dropbox.Dropbox(at); dbx.create_folder_v2('alma') Why can that be? Thanks
    – Marci
    Commented Oct 10, 2017 at 12:05
  • 1. You can make a single call to upload a file, e.g., to "/folder/file.ext", and "/folder" will automatically be created if it doesn't already exist. 2. Calling create_folder_v2 should create a folder, but check if you're getting any exception, or check what the result is. For example, the page should be like '/alma', not 'alma'.
    – Greg
    Commented Oct 10, 2017 at 13:09
  • AttributeError: 'Dropbox' object has no attribute 'create_folder_v2' The current version of dropbox is 8.2.0
    – Marci
    Commented Oct 10, 2017 at 15:03
  • Oh, in the Python SDK the full method name is files_create_folder_v2.
    – Greg
    Commented Oct 10, 2017 at 15:26
  • Thanks very much, Greg. You are really helpful as always.
    – Marci
    Commented Oct 10, 2017 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.