Media yang Didownload

Download media yang dapat dilanjutkan telah menjadi fitur di library klien .NET Google API sejak versi 1.4.0-beta. Library khusus Google API berisi metode praktis untuk berinteraksi fitur ini.

Protokol download media yang dapat dilanjutkan mirip dengan protokol upload media yang dapat dilanjutkan yang dijelaskan, misalnya, pada halaman upload media untuk Drive API.

Kelas utama yang diminati adalah MediaDownloader Dalam implementasi download media yang dapat dilanjutkan ini, konten media didownload dalam potongan (ukuran potongan dapat dikonfigurasi).

Kode Contoh

Jika metode dalam library khusus API berisi "supportsMediaDownload" dalam dokumen Discovery, lalu Download dan DownloadAsync metode praktis ini tersedia di class permintaan. Metode tersebut mendownload data media ke Stream yang Anda berikan. Contoh:
{
    // 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);
}