DownloadFile Method
Downloads the specified file.
Syntax
onedrive.downloadFile([callback])
Callback
The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).
The callback for this method is defined as:
function(err){ }
'err' is the error that occurred. If there was no error, then 'err' is 'null'.
'err' has 2 properties which hold detailed information:
err.code err.message
Remarks
This method downloads the specified file. Any of the following properties may be set to specify the file to download:
If LocalFile is set the file will be saved to the specified location. If LocalFile is not set the file data will be held by ResourceData.To decrypt an encrypted file set EncryptionAlgorithm and EncryptionPassword before calling this method.
onedrive.ResourceId = fileId; onedrive.LocalFile = "../MyFile.zip"; onedrive.DownloadFile();
Resuming Downloads
The class also supports resuming failed downloads by using the StartByte property. If the download was interrupted, set StartByte to the appropriate offset before calling this method to resume the download.
onedrive.ResourceId = fileId; onedrive.LocalFile = downloadFile; onedrive.DownloadFile(); //The transfer is interrupted and DownloadFile() above fails. Later, resume the download: //Get the size of the partially download file onedrive.StartByte = new FileInfo(downloadFile).Length; onedrive.ResourceId = fileId; onedrive.LocalFile = downloadFile; onedrive.DownloadFile();
Resuming Encrypted File Downloads
Resuming encrypted file downloads is only supported when LocalFile was set in the initial download attempt. When beginning an encrypted download if LocalFile is set the class will create a temporary file in TempPath to hold the encrypted data until it is complete.
If the download is interrupted DownloadTempFile will be populated with the temporary file holding the partial data.
When resuming, 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.
onedrive.ResourceId = fileId; onedrive.LocalFile = downloadFile; onedrive.EncryptionPassword = "password"; onedrive.DownloadFile(); //The transfer is interrupted and DownloadFile() above fails. Later, resume the download: //Get the size of the partially download temp file onedrive.StartByte = new FileInfo(onedrive.Config("DownloadTempFile")).Length; onedrive.ResourceId = fileId; onedrive.LocalFile = downloadFile; onedrive.EncryptionPassword = "password"; onedrive.DownloadFile();