Three Ways to Build Sharing Into a Dropbox App

Dropbox is a productive tool for storing personal files, but the real value emerges when you start collaborating. Whether you're coordinating with coworkers, sharing class materials, or working on a group project, the Dropbox API provides several ways to automate sharing. Here we'll walk through three approaches—shared links, file access, and shared folders—using the Dropbox Python SDK.

Getting Set Up

Before making any API calls, you'll need the Dropbox Python SDK and an access token for your Dropbox App. If you haven't created one yet, you can do so from the App Console, then grab your access token from the app settings.

Once your environment is ready, create a new file, import the SDK, and instantiate a Dropbox object with your token:

import dropbox
token = 'your_access_token'
dbx = dropbox.Dropbox(token)

Consider a professor recording student presentations. Videos of half an hour or more are too large to email, but they can be uploaded to Dropbox and shared instantly via a link. Shared links are the simplest option—recipients don't even need a Dropbox account to view the content. This also makes it easy to share one file with many people or an undefined group, such as a research group's website or chat.

Basic shared-link creation involves one call:

def creating_shared_link_no_settings(path):
    link = dbx.sharing_create_shared_link_with_settings(path)
    print(link.url)
 
creating_shared_link_no_settings("/students/Amy/video.mp4")

The link created here is a basic shared link with no custom settings, so team-specific sharing policies may apply on Dropbox Business accounts.

If you're posting a link to a public faculty site but want to keep student videos private, you can configure the link's settings. The sample below adds a password so that only those with the credentials can access the file, while optionally setting an expiration date (requires Python's built-in datetime module if you uncomment it):

def creating_shared_link_password(path, password):
    link_settings = dropbox.sharing.SharedLinkSettings(
        requested_visibility =
        dropbox.sharing.RequestedVisibility.password,
        link_password=password,
        #expires=datetime.datetime.utcnow() + datetime.timedelta(hours=24)
    )
    link = dbx.sharing_create_shared_link_with_settings(path, settings=link_settings)
    print(link.url)
 
creating_shared_link_password('/students/Amy/video.mp4','password')

Here, the visibility is set to require a password, which you supply separately from the link configuration.

Granting Direct File Access

Shared links work well for anyone, but for a classroom where every student already has a Dropbox account, direct file access is a more controlled choice. Sharing files this way requires recipients to be authenticated, allowing the sharer to see whether they've viewed the file. Recipients can also comment without leaving Dropbox.

Using the sharing/add_file_member endpoint, you can add students to a file individually by email and include a message so they know what they're receiving:

member = dropbox.sharing.MemberSelector.email('[email protected]')
dbx.sharing_add_file_member('/2019/Students/Amy_Thesis.mp4', [member], "Here's your thesis video.")

Important: with this method the recipient must have a Dropbox account to view the file. Also note that files are limited to viewer access; editing rights require a shared folder.

Creating a Shared Folder

If you want to enable editing collaboration rather than just viewing, you need a shared folder. This is useful when more than one person is contributing—for instance, a thesis committee where multiple professors provide feedback alongside the student. The sharing process involves several chained calls: files/create_folder, sharing/share_folder, and sharing/add_folder_member:

def creating_shared_folder(folder_path, access_level, email, message):
    dbx.files_create_folder(folder_path)
    # sharing_folder = dbx.sharing_share_folder(folder_path, force_async=True)
    sharing_folder = dbx.sharing_share_folder(folder_path)
    if sharing_folder.is_complete():
        sharing_folder_data = sharing_folder.get_complete()
    if sharing_folder.is_async_job_id():
        async_job_id = sharing_folder.get_async_job_id()
        # helper function will block until async sharing job completes
        retry_sharing_job(async_job_id)
        sharing_folder_job = dbx.sharing_check_share_job_status(async_job_id)
        sharing_folder_data = sharing_folder_job.get_complete()
 
    member = dropbox.sharing.MemberSelector.email(email)
    add_member = dropbox.sharing.AddMember(member, access_level)
    members = [add_member]
    dbx.sharing_add_folder_member(sharing_folder_data.shared_folder_id, members, custom_message=message)
    print(f"Folder successfully created and shared with {email}.")
 
creating_shared_folder(
    '/students/Amy',
    dropbox.sharing.AccessLevel.editor,
    '[email protected]',
    'This is the message they will see'
)

One caveat: the folder share operation can be asynchronous, in which case the response contains an async_job_id rather than a completion status. The retry logic below handles that possibility:

def retry_sharing_job(async_job_id):
    sharing_job = dbx.sharing_check_share_job_status(async_job_id)
    if sharing_job.is_complete():
        print("Async sharing job completed...")
        pass
    else:
        print("Async sharing job in progress")
        print("....waiting 3 seconds...")
        time.sleep(3)
        retry_sharing_job(async_job_id)

When sharing a folder with the function in the sample above, you'll set four parameters:

  1. folder_path – the path and name of the folder, e.g. /students/Amy; make sure the path starts with a slash.
  2. access_level – the sharing permission, e.g. editor for collaborators who need to add files or submit reflections.
  3. email – recipient's email address.
  4. message – explanation the recipient sees in the notification.

If you have a list of students, you can iterate over it and share a folder with everyone at once:

students = [('Amy', '[email protected]'), ('Bill', '[email protected]'), ('Chad', '[email protected]')]
 
for name, email in students:
    creating_shared_folder(f'/students/{name}', dropbox.sharing.AccessLevel.editor, email, 'Here is your talk')

The advantage of folders over files is that you can add more files later (grades, notes, instructions) without re-sharing each time.

Choosing the Right Sharing Method

All three approaches have their sweet spots:

  • Shared links are ideal for view-only access and for recipients who aren't Dropbox users. Passwords and expirations are easy to add.
  • Direct file sharing makes sense when the recipient is on Dropbox and needs the ability to view and comment, with the option to track views.
  • Shared folders work best for ongoing collaboration where multiple members need edit access and where shared resources will grow over time.

Whether you're organizing research reviews, one-on-one meeting notes, or company announcements, you can build these patterns into your app with the Dropbox API and let automation handle the overhead of collaboration.