IPWorks Cloud 2020 C++ Edition

Questions / Feedback?

DownloadFile Method

Downloads, and optionally converts, a file.

Syntax

ANSI (Cross Platform)
int DownloadFile(const char* lpszResourceId, const char* lpszMimeType);

Unicode (Windows)
INT DownloadFile(LPCWSTR lpszResourceId, LPCWSTR lpszMimeType);
- (void)downloadFile:(NSString*)resourceId :(NSString*)mimeType;
#define MID_GOOGLEDRIVE_DOWNLOADFILE 11

IPWORKSCLOUD_EXTERNAL int IPWORKSCLOUD_CALL IPWorksCloud_GoogleDrive_Do(void *lpObj, int methid, int cparam, void *param[], int cbparam[], int64 *lpllVal);

Remarks

This method downloads the file specified by ResourceId.

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.

If the empty string is passed for MimeType, the file will be downloaded as-is. If the file is in one of the Google formats shown in the table below, one of the MIME types shown in the third column can be passed for MimeType instead to convert the file before downloading it.

Google FormatDownload Format MIME Type
Google Docs HTML text/html
Plain text text/plain
Rich text application/rtf
Open Office document application/vnd.oasis.opendocument.text
PDF application/pdf
MS Word application/vnd.openxmlformats-officedocument.wordprocessingml.document
Google Sheets MS Excel application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Open Office sheet application/x-vnd.oasis.opendocument.spreadsheet
PDF application/pdf
CSV (first sheet only) text/csv
Google Drawing JPEG image/jpeg
PNG image/png
SVG image/svg+xml
PDF image/pdf
Google Slides MS Powerpoint application/vnd.openxmlformats-officedocument.presentationml.presentation
PDF application/pdf
Plain text text/plain
Google App Scripts JSON application/vnd.google-apps.script+json

Download Notes

Downloading an Encrypted File

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

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

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

//Get the size of the partially downloaded file
googledrive.StartByte = new FileInfo(downloadFile).Length;
googledrive.DownloadFile(googledrive.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.

googledrive.LocalFile = "../MyFile.zip";
googledrive.EncryptionPassword = "password";
googledrive.DownloadFile(googledrive.Resource[0].Id, "");

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

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

Error Handling (C++)

This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)

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