IPWorks Cloud 2020 Kotlin Edition

Questions / Feedback?

DownloadFile Method

Downloads a file.

Syntax

public fun downloadFile(filePath: String?)

Remarks

This method downloads the file at the specified FilePath in the share currently selected by Share.

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 will be saved to the specified location; otherwise, the file data will be held by ResourceData.

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:

azurefile.LocalFile = "../MyFile.zip";
azurefile.DownloadFile(azurefile.Resources[0].Path);

Resuming Downloads

The component 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 = "../MyFile.zip";
azurefile.LocalFile = downloadFile;
azurefile.DownloadFile(azurefile.Resources[0].Path);

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

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

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 component 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.

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

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

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

Copyright (c) 2021 /n software inc. - All rights reserved.
IPWorks Cloud 2020 Kotlin Edition - Version 20.0 [Build 7941]