IPWorks Cloud 2020 PHP Edition

Questions / Feedback?

DownloadFile Method

Downloads a file resource.

Object Oriented Interface

public function doDownloadFile($resource);

Procedural Interface

ipworkscloud_dropbox_do_downloadfile($res, $resource);

Remarks

This method downloads the file resource specified by Resource. If the AllowFolderDownloads configuration setting is enabled, it can also be used to download a folder resource as a ZIP file.

Resource must be a path, an Id-based relative path, a resource Id, or (for file resources only) a revision Id.

For file resources, the DownloadType property can be used to control whether this method downloads the file contents (default), a file preview, or a file thumbnail. The latter two options are only available for certain file types; refer to DownloadType for more information.

Note that certain file resources are "export-only"; when downloading such a file resource to a LocalFile, the class will append the file extension of export file format (if the name of the given LocalFile does not already end with said extension). Refer to the ResourceExportExtension property for more information.

If 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:

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

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

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

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

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.

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

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

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

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