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 installed (
pip install "boxsdk~=10") - 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_fileruns 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
Theupload_big_file method uploads the file in parts automatically. Run a
preflight check first so that you can handle name conflicts before you start the
upload. When a file with the same name already exists, upload_chunked_file
creates a session for the existing file and uploads a new version with the
upload_file_via_session helper shown in the next section.
Python v10
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
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
