@@ -194,9 +194,14 @@ Chunked Upload
194
194
--------------
195
195
196
196
For 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
198
198
without aborting the entire upload, and failed parts can then be retried.
199
199
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
+
200
205
### Automatic Uploader
201
206
202
207
Since 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
211
216
#### Upload new file
212
217
213
218
The 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 ]
217
224
object that was uploaded.
218
225
219
226
<!-- samples x_chunked_uploads automatic -->
@@ -224,7 +231,10 @@ uploaded_file = chunked_uploader.start()
224
231
print (f ' File " { uploaded_file.name} " uploaded to Box with file ID { uploaded_file.id} ' )
225
232
```
226
233
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
228
238
method [ ` upload_session.get_chunked_uploader_for_stream(content_stream, file_size) ` ] [ get_chunked_uploader_for_stream ] .
229
239
230
240
``` python
@@ -240,14 +250,14 @@ with open(test_file_path, 'rb') as content_stream:
240
250
#### Upload new file version
241
251
242
252
To 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 ]
244
254
to retrieve a [ ` ChunkedUploader ` ] [ chunked_uploader_class ] object. Calling the method [ ` chunked_upload.start() ` ] [ start ]
245
255
will kick off the chunked upload process and return the updated [ File] [ file_class ] .
246
256
247
257
<!-- samples x_chunked_uploads automatic_new_version -->
248
258
``` python
249
259
# 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' )
251
261
uploaded_file = chunked_uploader.start()
252
262
print (f ' File " { uploaded_file.name} " uploaded to Box with file ID { uploaded_file.id} ' )
253
263
# the uploaded_file.id will be the same as 'existing_big_file_id'
@@ -293,17 +303,6 @@ except:
293
303
print (f ' File " { uploaded_file.name} " uploaded to Box with file ID { uploaded_file.id} ' )
294
304
```
295
305
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
-
307
306
[ resume ] : https://box-python-sdk.readthedocs.io/en/latest/boxsdk.object.html#boxsdk.object.chunked_uploader.ChunkedUploader.resume
308
307
309
308
#### Abort Chunked Upload
@@ -317,7 +316,7 @@ from boxsdk.exception import BoxNetworkException
317
316
test_file_path = ' /path/to/large_file.mp4'
318
317
content_stream = open (test_file_path, ' rb' )
319
318
total_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 ' )
321
320
try :
322
321
uploaded_file = chunked_uploader.start()
323
322
except BoxNetworkException:
@@ -371,8 +370,10 @@ The individual endpoint methods are detailed below:
371
370
#### Create Upload Session for File Version
372
371
373
372
To 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
376
377
[ ` UploadSession ` ] [ upload_session_class ] object representing the created upload session.
377
378
378
379
<!-- sample post_files_id_upload_sessions -->
@@ -388,9 +389,10 @@ print(f'Created upload session {upload_session.id} with chunk size of {upload_se
388
389
#### Create Upload Session for File
389
390
390
391
To 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.
394
396
395
397
<!-- sample post_files_upload_sessions -->
396
398
``` python
0 commit comments