IPWorks Cloud 2020 Python Edition

Questions / Feedback?

download_file Method

Downloads a file resource.

Syntax

def download_file(file_id: str) -> None: ...

Remarks

This method downloads the file resource specified by FileId.

The download_type property can be used to control whether this method downloads the file contents (default) or a file thumbnail. Refer to download_type for more information.

If local_file is set, the file will be saved to the specified location; otherwise, the file data will be held by resource_data.

To download and decrypt an encrypted file, set encryption_algorithm and encryption_password before calling this method.

Download Notes

In the simplest use-case, downloading a file looks like this:

box.LocalFile = "../MyFile.zip";
box.DownloadFile(box.Resources[0].Id);

Resuming Downloads

The class also supports resuming failed downloads by using the start_byte property. If a download is interrupted, set start_byte to the appropriate offset before calling this method to resume the download.

string downloadFile = "../MyFile.zip";
box.LocalFile = downloadFile;
box.DownloadFile(box.Resources[0].Id);

//The transfer is interrupted and DownloadFile() above fails. Later, resume the download:

//Get the size of the partially downloaded file
box.StartByte = new FileInfo(downloadFile).Length;
box.DownloadFile(box.Resources[0].Id);

Resuming Encrypted File Downloads

Resuming encrypted file downloads is only supported when local_file was set in the initial download attempt.

If local_file is set when beginning an encrypted download, the class creates a temporary file in TempPath to hold the encrypted data until the download is complete. If the download is interrupted, DownloadTempFile will be populated with the path of the temporary file that holds the partial data.

To resume, DownloadTempFile must be populated, along with start_byte, to allow the remainder of the encrypted data to be downloaded. Once the encrypted data is downloaded it will be decrypted and written to local_file.

box.LocalFile = "../MyFile.zip";
box.EncryptionPassword = "password";
box.DownloadFile(box.Resources[0].Id);

//The transfer is interrupted and DownloadFile() above fails. Later, resume the download:

//Get the size of the partially download temp file
box.StartByte = new FileInfo(box.Config("DownloadTempFile")).Length;
box.DownloadFile(box.Resources[0].Id);

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