Resumable media download has been a feature in the Google API .NET client library since 1.4.0-beta. The Google API-specific libraries contain convenience methods for interacting with this feature.
The resumable media download protocol is similar to the resumable media upload protocol which is described, for example, on the media upload page for the Drive API.
The main class of interest is
MediaDownloader
.
In this implementation of resumable media download, the media content is downloaded in chunks (chunk size is configurable).
Sample Code
If methods in the API-specific libraries contain the "supportsMediaDownload
" parameter in the Discovery document,
then the Download
and DownloadAsync
convenience methods are available in the request class.
Those methods download the media data into a Stream
object that you provide. For example:
{ // Create the service using the client credentials. var storageService = new StorageService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "APP_NAME_HERE" }); // Get the client request object for the bucket and desired object. var getRequest = storageService.Objects.Get("BUCKET_HERE", "OBJECT_HERE"); using (var fileStream = new System.IO.FileStream( "FILE_PATH_HERE", System.IO.FileMode.Create, System.IO.FileAccess.Write)) { // Add a handler which will be notified on progress changes. // It will notify on each chunk download and when the // download is completed or failed. getRequest.MediaDownloader.ProgressChanged += Download_ProgressChanged; getRequest.Download(fileStream); } } static void Download_ProgressChanged(IDownloadProgress progress) { Console.WriteLine(progress.Status + " " + progress.BytesDownloaded); }