Skip to content

OneDrive Files

Upload, download, share, manage, and track files in OneDrive for Business — the most common file operations, shown end-to-end on throwaway files so each example is safe to re-run.


Prerequisites

Permission Description Reference
Files.Read Read files, search, delta, analytics Files permissions
Files.ReadWrite Upload, download, manage, share files Files permissions
Files.ReadWrite.All Recycle bin access Files permissions
Analytics.Read File analytics Analytics permissions

Most examples authenticate with username/password (client_id, username, password from tests.settings); a few use client secret.


How the file operations fit together

graph TD
    subgraph "Upload & download"
        U["upload_download /<br/>ensure_file /<br/>upload_large /<br/>download_json"]
    end

    subgraph "Lifecycle"
        M["manage<br/>(copy / rename / move /<br/>versions / delete)"]
        L["lifecycle<br/>(checkout → edit → checkin)"]
        R["recycle_bin<br/>(restore / purge)"]
    end

    subgraph "Discover & collaborate"
        S["search / delta_query / analytics"]
        SH["sharing<br/>(links / invitations)"]
    end

    U --> M
    M --> L
    M --> R
    S --> U
    SH --> M

Which example to use: upload a file the first time (upload_download.py), provision one idempotently (ensure_file.py), large files via resumable sessions (upload_large.py), reading structured data back (download_json.py), then manage it (manage.py), publish versions with check-out/check-in (lifecycle.py), recover deletions (recycle_bin.py), share it (sharing.py), and keep a local cache in sync (delta_query.py).


Examples

Operation File Permission API
Upload and download a file (round-trip) upload_download.py Files.ReadWrite put content
Ensure a file exists (idempotent get-or-upload) ensure_file.py Files.ReadWrite put content
Download and read a JSON file download_json.py Files.ReadWrite get content
Upload a large file (resumable session) upload_large.py Files.ReadWrite create upload session
Copy, rename, move, versions, delete manage.py Files.ReadWrite copy
Check out, edit, check in (versioning) lifecycle.py Files.ReadWrite checkout
Recycle bin — restore and purge recycle_bin.py Files.ReadWrite.All recycleBin
Sharing links and invitations sharing.py Files.ReadWrite create link
Search files by keyword search.py Files.Read search
Delta query with resume token delta_query.py Files.Read delta
Largest files report largest_files.py Files.Read list children
Sharing audit — files with links find_shared.py Files.Read.All permission list
File analytics and activity analytics.py Files.Read, Analytics.Read analytics

API reference