IPWorks Cloud 2020 Java Edition

Questions / Feedback?

DownloadFile Method

Downloads a file by name.

Syntax

public void downloadFile(String bucketName, String fileName);

Remarks

This method downloads the latest version of the file named FileName from the bucket named BucketName. The Range property can optionally be set before calling this method to download a specific range of data from the file.

This method can be used to download files that are owned by other accounts, so long as an appropriate download authorization token and download URL are supplied using the DownloadAuthToken and DownloadURL configuration settings; refer to their documentation for more information.

If a stream has been specified using SetDownloadStream, the file data will be sent through it. If a stream is not specified, and LocalFile is set, the file data will be saved to the specified location; otherwise, the file data will be held by FileData.

To download and decrypt an encrypted file, set EncryptionAlgorithm and EncryptionPassword before calling this method.

Download Notes

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

b2.LocalFile = "../MyData.zip";
b2.DownloadFile("MyBucket", "data.zip"); // Or, DownloadFileById().

Resuming Downloads

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

string downloadFile = "../MyData.zip";
b2.LocalFile = downloadFile;
b2.DownloadFile("MyBucket", "data.zip"); // Or, DownloadFileById().

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

//Get the size of the partially downloaded file
b2.StartByte = new FileInfo(downloadFile).Length;
b2.DownloadFile("MyBucket", "data.zip"); // Or, DownloadFileById().

Resuming Encrypted File Downloads

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

If LocalFile 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 StartByte, to allow the remainder of the encrypted data to be downloaded. Once the encrypted data is downloaded it will be decrypted and written to LocalFile.

b2.LocalFile = "../MyData.zip";
b2.EncryptionPassword = "password";
b2.DownloadFile("MyBucket", "data.zip"); // Or, DownloadFileById().

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

//Get the size of the partially downloaded temp file
b2.StartByte = new FileInfo(b2.Config("DownloadTempFile")).Length;
b2.DownloadFile("MyBucket", "data.zip"); // Or, DownloadFileById().

The currently-authenticated application key must have the readFiles capability (unless the bucket is public) to call this method successfully, otherwise the server will return an error. Refer to the Account.Capabilities field for more information.

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