IPWorks Cloud 2020 Python Edition

Questions / Feedback?

upload_file Method

Uploads a new file resource.

Syntax

def upload_file(file_name: str, parent_id: str) -> str: ...

Remarks

This method uploads a new file resource named FileName to the folder specified by ParentId. The Id of the newly-created file resource is returned.

FileName must be no longer than 255 characters; may not contain /, \, non-printable ASCII characters, or trailing whitespace; and cannot be one of the special names . or ...

ParentId can be empty, in which case the file is uploaded to the root folder.

The ClientCreatedTime and ClientModifiedTime configuration settings may be set before calling this method to submit those timestamps along with the file data.

If local_file is set the file will be uploaded from the specified path. If local_file is not set the data in resource_data will be used.

To encrypt the file before uploading it, set encryption_algorithm and encryption_password.

Upload Notes

Box offers two ways to upload a file. For smaller files a simple upload option is provided to upload data in one request. This is the default option. For larger files (must be larger than 20 MB), uploads can be fragmented into multiple pieces, allowing resuming of uploads that may be interrupted.

Simple

By default the class uses the simple upload mechanism. When doing a simple upload, the HashSimpleUploads setting is applicable.

box.LocalFile = "../MyFile.zip";
box.UploadFile("MyFile.zip", "");

Resumable

To enable resumable uploads set use_resumable_upload to True. This is recommended for large files (must be larger than 20 MB). The class will automatically fragment the specified file into smaller pieces and upload each individually.

When use_resumable_upload is set to True and upload_file is called, a resumable upload session is started by the class. resume_url is populated with a URL identifying the session (this value may be needed for additional operations if the upload does not complete normally).

During a resumable upload, the on_fragment_complete event fires after each fragment is uploaded to indicate overall progress. The class also updates start_byte as necessary to indicate the current offset in the file.

If the upload is interrupted for any reason, resuming it is easy. First, verify that resume_url is populated (if the same instance of the class is used, it should already be populated, and no special action should be needed). Call poll_upload_status to populate the correct values for start_byte and UploadFragmentSize. Then call upload_file again to resume the upload at the specified start_byte offset.

Note that if the upload is not resumed after some time the upload session will expire. poll_upload_status may be used to check the status of a resumable upload, including when it will expire (which is stored in the UploadExpDate configuration setting). An interrupted upload can be aborted explicitly using the abort_upload method.

box.LocalFile = "../MyFile.zip";
box.UploadFile("MyFile.zip", "");

//The transfer is interrupted and UploadFile() above fails. Later, resume the download.
//Using the same instance StartByte and ResumeURL are already populated from the previous
//upload attempt.
box.UploadFile("MyFile.zip", "");

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks Cloud 2020 Python Edition - Version 20.0 [Build 8265]