@@ -194,9 +194,14 @@ Chunked Upload
194194--------------
195195
196196For large files or in cases where the network connection is less reliable,
197- you may want to upload the file in parts. This allows a single part to fail
197+ you may want to upload the file in parts. This allows a single part to fail
198198without aborting the entire upload, and failed parts can then be retried.
199199
200+ Since box-python-sdk 3.11.0 release, by default the SDK uses upload urls provided in response
201+ when creating a new upload session. This allowes to always upload your content to the closest Box data center and
202+ can significantly improve upload speed. You can always disable this feature and always use base upload url by
203+ setting ` use_upload_session_urls ` flag to ` False ` when creating upload session.
204+
200205### Automatic Uploader
201206
202207Since box-python-sdk 3.7.0 release, automatic uploader uses multiple threads, which significantly speeds up the upload process.
@@ -211,9 +216,11 @@ API.CHUNK_UPLOAD_THREADS = 6
211216#### Upload new file
212217
213218The SDK provides a method of automatically handling a chunked upload. First get a folder you want to upload the file to.
214- Then call [ ` folder.get_chunked_uploader(file_path, rename_file=False) ` ] [ get_chunked_uploader_for_file ] to retrieve
215- a [ ` ChunkedUploader ` ] [ chunked_uploader_class ] object. Calling the method [ ` chunked_upload.start() ` ] [ start ] will
216- kick off the chunked upload process and return the [ File] [ file_class ]
219+ Then call [ ` folder.get_chunked_uploader(file_path, rename_file=False, use_upload_session_urls=True) ` ] [ get_chunked_uploader_for_file ]
220+ to retrieve a [ ` ChunkedUploader ` ] [ chunked_uploader_class ] object. Setting ` use_upload_session_urls ` to ` True ` inilializes
221+ the uploader that utlizies urls returned by the ` Create Upload Session ` endpoint response unless a custom
222+ API.UPLOAD_URL was set in the config. Setting ` use_upload_session_urls ` to ` False ` inilializes the uploader that uses always base upload urls.
223+ Calling the method [ ` chunked_upload.start() ` ] [ start ] will kick off the chunked upload process and return the [ File] [ file_class ]
217224object that was uploaded.
218225
219226<!-- samples x_chunked_uploads automatic -->
@@ -224,7 +231,10 @@ uploaded_file = chunked_uploader.start()
224231print (f ' File " { uploaded_file.name} " uploaded to Box with file ID { uploaded_file.id} ' )
225232```
226233
227- You can also upload file stream by creating a [ ` UploadSession ` ] [ upload_session_class ] first and then calling the
234+ You can also upload file stream by creating a [ ` UploadSession ` ] [ upload_session_class ] first. This can be done by calling
235+ [ ` folder.create_upload_session(file_size, file_name=None, use_upload_session_urls=True) ` ] [ create_upload_session ] method.
236+ ` use_upload_session_urls ` flag is used to determine if the upload session should use urls returned by
237+ the ` Create Upload Session ` endpoint or should it always use base upload urls. Then you can call
228238method [ ` upload_session.get_chunked_uploader_for_stream(content_stream, file_size) ` ] [ get_chunked_uploader_for_stream ] .
229239
230240``` python
@@ -240,14 +250,14 @@ with open(test_file_path, 'rb') as content_stream:
240250#### Upload new file version
241251
242252To upload a new file version for a large file, first get a file you want to replace.
243- Then call [ ` file.get_chunked_uploader(file_path) ` ] [ get_chunked_uploader_for_version ]
253+ Then call [ ` file.get_chunked_uploader(file_path, rename_file=False, use_upload_session_urls=True ) ` ] [ get_chunked_uploader_for_version ]
244254to retrieve a [ ` ChunkedUploader ` ] [ chunked_uploader_class ] object. Calling the method [ ` chunked_upload.start() ` ] [ start ]
245255will kick off the chunked upload process and return the updated [ File] [ file_class ] .
246256
247257<!-- samples x_chunked_uploads automatic_new_version -->
248258``` python
249259# uploads new large file version
250- chunked_uploader = client.file(' existing_big_file_id' ).get_chunked_uploader(' /path/to/file' )
260+ chunked_uploader = client.file(' existing_big_file_id' ).get_chunked_uploader(file_path = ' /path/to/file' )
251261uploaded_file = chunked_uploader.start()
252262print (f ' File " { uploaded_file.name} " uploaded to Box with file ID { uploaded_file.id} ' )
253263# the uploaded_file.id will be the same as 'existing_big_file_id'
@@ -293,17 +303,6 @@ except:
293303print (f ' File " { uploaded_file.name} " uploaded to Box with file ID { uploaded_file.id} ' )
294304```
295305
296- Alternatively, you can also create a [ ` UploadSession ` ] [ upload_session_class ] object by calling
297- [ ` client.upload_session(session_id) ` ] [ upload_session ] if you have the upload session id. This can be helpful in
298- resuming an existing upload session.
299-
300-
301- ``` python
302- chunked_uploader = client.upload_session(' 12345' ).get_chunked_uploader(' /path/to/file' )
303- uploaded_file = chunked_uploader.resume()
304- print (f ' File " { uploaded_file.name} " uploaded to Box with file ID { uploaded_file.id} ' )
305- ```
306-
307306[ resume ] : https://box-python-sdk.readthedocs.io/en/latest/boxsdk.object.html#boxsdk.object.chunked_uploader.ChunkedUploader.resume
308307
309308#### Abort Chunked Upload
@@ -317,7 +316,7 @@ from boxsdk.exception import BoxNetworkException
317316test_file_path = ' /path/to/large_file.mp4'
318317content_stream = open (test_file_path, ' rb' )
319318total_size = os.stat(test_file_path).st_size
320- chunked_uploader = client.upload_session( ' 56781 ' ).get_chunked_uploader_for_stream(content_stream, total_size )
319+ chunked_uploader = client.file( ' existing_big_file_id ' ).get_chunked_uploader( file_path = ' /path/to/file ' )
321320try :
322321 uploaded_file = chunked_uploader.start()
323322except BoxNetworkException:
@@ -371,8 +370,10 @@ The individual endpoint methods are detailed below:
371370#### Create Upload Session for File Version
372371
373372To create an upload session for uploading a large version, call
374- [ ` file.create_upload_session(file_size, file_name=None) ` ] [ create_version_upload_session ] with the size of the file to be
375- uploaded. You can optionally specify a new ` file_name ` to rename the file on upload. This method returns an
373+ [ ` file.create_upload_session(file_size, file_name=None, use_upload_session_urls=True) ` ] [ create_version_upload_session ]
374+ with the size of the file to be uploaded. You can optionally specify a new ` file_name ` to rename the file on upload.
375+ ` use_upload_session_urls ` flag is used to determine if the upload session should use urls returned by
376+ the ` Create Upload Session ` endpoint or should it always use base upload urls. This method returns an
376377[ ` UploadSession ` ] [ upload_session_class ] object representing the created upload session.
377378
378379<!-- sample post_files_id_upload_sessions -->
@@ -388,9 +389,10 @@ print(f'Created upload session {upload_session.id} with chunk size of {upload_se
388389#### Create Upload Session for File
389390
390391To create an upload session for uploading a new large file, call
391- [ ` folder.create_upload_session(file_size, file_name) ` ] [ create_upload_session ] with the size and filename of the file
392- to be uploaded. This method returns an [ ` UploadSession ` ] [ upload_session_class ] object representing the created upload
393- session.
392+ [ ` folder.create_upload_session(file_size, file_name, use_upload_session_urls=True) ` ] [ create_upload_session ] with
393+ the size and filename of the file to be uploaded. ` use_upload_session_urls ` flag is used to determine if the upload
394+ session should use urls returned by the ` Create Upload Session ` endpoint or should it always use base upload urls.
395+ This method returns an [ ` UploadSession ` ] [ upload_session_class ] object representing the created upload session.
394396
395397<!-- sample post_files_upload_sessions -->
396398``` python
0 commit comments