-
Notifications
You must be signed in to change notification settings - Fork 0
File Upload
Jiri Formacek edited this page Jul 4, 2026
·
1 revision
Uploads a local file to Microsoft Graph (OneDrive, SharePoint, Teams, etc.) using the resumable upload session protocol. The file is split into 5 MB chunks and uploaded sequentially.
Tip: Use
-Verboseto monitor upload progress chunk by chunk.
| Parameter | Type | Required | Description |
|---|---|---|---|
LocalFilePath |
String |
Yes | Full local path to the file to upload. The file must exist and be readable. |
GraphFilePath |
String |
Yes | Microsoft Graph API path for the destination, without the :/createUploadSession suffix. |
ConflictBehavior |
String |
No | What to do when a file already exists: replace (default), rename, or fail. |
None. The function streams chunk requests silently. Use -Verbose for progress.
# Upload to the current user's OneDrive
Add-GraphLargeFile `
-LocalFilePath 'C:\Reports\annual-report.xlsx' `
-GraphFilePath '/me/drive/root:/Reports/annual-report.xlsx'# Upload with verbose progress
Add-GraphLargeFile `
-LocalFilePath 'C:\Videos\training.mp4' `
-GraphFilePath 'https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root:/Videos/training.mp4' `
-Verbose# Rename instead of replace on conflict
Add-GraphLargeFile `
-LocalFilePath 'C:\Exports\data.csv' `
-GraphFilePath '/me/drive/root:/Exports/data.csv' `
-ConflictBehavior rename# Fail on conflict (useful to prevent accidental overwrites)
Add-GraphLargeFile `
-LocalFilePath 'C:\Archive\backup.zip' `
-GraphFilePath '/me/drive/root:/Archive/backup.zip' `
-ConflictBehavior fail- The command calls
POST {GraphFilePath}:/createUploadSessionto obtain an upload URL. - The file is read in 5 MB chunks (320 KB × 16).
- Each chunk is sent with a
Content-Rangeheader (bytes start-end/total). - The upload URL is valid for a limited time (typically 24 hours). If the upload fails midway, the session may expire before a retry.
The GraphFilePath must point to a driveItem path with the file name as the last segment:
| Destination | Example path |
|---|---|
| Current user's OneDrive | /me/drive/root:/Folder/file.txt |
| Another user's OneDrive | /users/{userId}/drive/root:/Folder/file.txt |
| SharePoint site drive | /sites/{siteId}/drive/root:/Folder/file.txt |
| SharePoint document library by path | /drives/{driveId}/root:/path/to/file.txt |
You can also use absolute URLs:
Add-GraphLargeFile `
-LocalFilePath 'C:\file.pdf' `
-GraphFilePath 'https://graph.microsoft.com/v1.0/me/drive/root:/Docs/file.pdf'- Uses
Invoke-GraphWithRetryinternally for session creation and each chunk PUT, so throttling is handled automatically. - The file stream is always closed in a
finallyblock, even if upload fails. - For files under ~4 MB, a direct
Invoke-GraphWithRetry -Method Putcall to the driveItem content endpoint may be simpler. - Reference: Microsoft Graph — Create upload session
Configuration
Making API Calls
Directory Objects
Files
Diagnostics
Reference