The code samples in this tutorial use the
.
Prerequisites
- A Box application with the scope (
root_readwrite) enabled - Python 3.8 or later installed on your computer
- The Box Python SDK v10.16.0 or later installed (
pip install "boxsdk>=10.16") - An authenticated
Direct upload
To upload a file, call theupload_file method. For more information about the direct upload API, see
.
Run a first. If
a file with the same name already exists, the error response includes the
conflicting file ID. If you don’t want to override the content of the file with
that name, change the name and upload it as a new file. The sample below assumes
you want to override the file content, so it uses that ID to upload a
:
Python v10
upload_file on a folder creates a new file. Calling
upload_file_version on an existing file uploads a new version.
Chunked upload
Use for files that are 20 MB or larger. Every chunked upload works through an : you create a session, , and to finalize the file. You have two options:- Convenience method:
upload_big_fileorupload_big_file_versionruns all three steps for you. - Manual upload session: create the session, upload each part, and commit it yourself when you need full control.
Convenience method
The SDK uploads the file in parts for you:upload_big_fileuploads a new file to a folder.upload_big_file_versionuploads a new version of an existing file. Before it uploads each part, it checks whether Box already stores that part from the previous version and skips it if so, so the upload is faster. For details, see .
upload_chunked_file uses the conflicting file ID to upload a new version with
upload_big_file_version:
Python v10
upload_big_file returns the new file. upload_big_file_version returns the
updated file, or None when the
returns 202 Accepted instead of a file.
Manual upload session
For full control over the upload, manage the session yourself. Theupload_file_via_session helper uploads every part and commits the session for
a session you pass in:
Python v10
This helper uploads every part, even when most of a new version matches the
previous version. To skip unchanged parts, use
upload_big_file_version, or
with create_file_upload_session_plan_by_url and only upload the parts listed
in misses.create_file_upload_session for a new file. When a file with the same name
already exists, upload_file_manual falls back to
create_file_upload_session_for_existing_file to upload a new version:
Python v10
