cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Upload file to sharing folder using Python Package

Upload file to sharing folder using Python Package

urvisheth
New member | Level 2
Go to solution

I want to figure out how I can upload a file to sharing folder. I have tried following code to upload a file to dropbox. Rather than uploading the file to shared folder "Reports", it uploaded it to my "userfolder/Reports" I tried various options but nothing worked out. I was able to get the shared folder id for the shared folder but there is no shared_path set for the folder. Let me know what else I can do.

 

 

 

 

 

import dropbox


DROPBOX_ACCESS_TOKEN = 'TOKEN'


def dropbox_connect():
    """Create a connection to Dropbox."""

    try:
        dbx = dropbox.Dropbox(DROPBOX_ACCESS_TOKEN)
        print('Connected to Dropbox successfully')
    except AuthError as e:
        print('Error connecting to Dropbox with access token: ' + str(e))
    return dbx

    

dbx = dropbox_connect()

file_path = 'PATHNAME'

# Specify the path to the folder. Here Reports should be a shared folder
destination_path = '/Reports/test.pdf'


# Upload the file to the folder
try:
    with open(file_path, 'rb') as file:
        response = dbx.files_upload(file.read(), destination_path)
        print('File uploaded to shared folder:', response.name)
except FileNotFoundError:
    print('File not found:', file_path)
except dropbox.exceptions.ApiError as e:
    print('Error uploading file:', e)

 

 

 

 

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

@urvisheth I see you want to upload a file to a shared folder in your team space, not your own folder. By default, API calls operate in the "member folder" of the connected account, not the "team space". You can configure API calls to operate in the "team space" instead though. To do so, you'll need to set the "Dropbox-API-Path-Root" header. You can find information on this in the Team Files Guide. With the Python SDK, you can set that header using the with_path_root method.

View solution in original post

2 Replies 2

Здравко
Legendary | Level 20
Go to solution

Hi @urvisheth,

If nothing else has been set, by default all file/folder path are rooted on the user folder, not to something else! On individual accounts user folder match to the account root and that why nothing need to be added. On group account, like business subscription, one account has more users and that's why both folder differs. To access something with account root based path or based to some other namespace, you have to set that namespace, the one that's not the default. 😉

Hope this gives direction.

Greg-DB
Dropbox Staff
Go to solution

@urvisheth I see you want to upload a file to a shared folder in your team space, not your own folder. By default, API calls operate in the "member folder" of the connected account, not the "team space". You can configure API calls to operate in the "team space" instead though. To do so, you'll need to set the "Dropbox-API-Path-Root" header. You can find information on this in the Team Files Guide. With the Python SDK, you can set that header using the with_path_root method.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?