File Upload and Download
Canvas workflows require robust file handling for course resources, assignment submissions, submission comments, and bulk grading workflows.
Downloads
Commands:
bash
canvas files download FILE_ID --out PATH
canvas files download-course --course COURSE_ID --out DIR
canvas submissions download --course COURSE_ID --assignment ASSIGNMENT_ID --out DIRRules:
- never overwrite existing files unless
--overwrite - write temp file then atomic rename
- preserve original filename when safe
- sanitize path components
- emit manifest for bulk operations
- progress goes to stderr
- JSON result includes file metadata and local path
Uploads
Commands:
bash
canvas assignments submit --course COURSE_ID ASSIGNMENT_ID --file PATH
canvas files upload --course COURSE_ID --folder FOLDER_ID --file PATH
canvas submissions comment --course COURSE_ID --assignment ASSIGNMENT_ID --user USER_ID --file PATHRules:
- validate local file path
- detect size and content type
- show dry-run summary before upload when requested
- include uploaded file IDs in JSON result
- record audit event for remote mutations
The Canvas file upload process requires implementing the full 3-step flow via a shared helper:
- Step 1: Notify Canvas.
POSTto the appropriate/api/v1/...file endpoint (e.g./api/v1/courses/{id}/filesor/api/v1/courses/{id}/assignments/{id}/submissions/{user_id}/files) with the file'sname,size, andcontent_type. This returns anupload_urlandupload_params. - Step 2: Upload file.
POSTto the returnedupload_urlusing multipart/form-data. Include allupload_paramsas form fields, and attach the file content. - Step 3: Follow redirect / finalize. Canvas responds to Step 2 with either a
201 Createdcontaining the final file info, or a3xx Redirect. If a redirect is returned, issue aGET(orPOST, depending on the endpoint) to theLocationheader to finalize the upload and receive the final file JSON.
Bulk submission download manifest
json
{
"course_id": "123",
"assignment_id": "456",
"generated_at": "2026-06-12T19:20:00Z",
"items": [
{
"user_id": "111",
"submission_id": "222",
"attempt": 1,
"file_id": "333",
"filename": "paper.pdf",
"local_path": "assignment-456/user_111/submission-222_paper.pdf",
"status": "downloaded"
}
]
}Platform notes
- Path sanitization: Student names may contain characters invalid in filenames (e.g.,
/,\,:,*). Sanitize by replacing these with_. - Cross-platform paths: Config and audit paths are resolved via
os.UserConfigDir()/os.UserStateDir(), which return OS-appropriate directories on Linux, macOS, and Windows automatically.