הורדת מדיה

האפשרות להוריד מדיה שניתן להמשיך היא תכונה בספריית הלקוח של Google API .NET מאז גרסה 1.4.0 בטא. הספריות הספציפיות ל-Google API מכילות שיטות נוחות לאינטראקציה עם בתכונה הזו.

הפרוטוקול להורדת מדיה שניתן להמשיך דומה לפרוטוקול של העלאת מדיה שניתן להמשיך, מתואר, לדוגמה, דף העלאת מדיה ל-Drive API.

סיווג העניין העיקרי הוא MediaDownloader ביישום הזה של הורדת מדיה שניתן להמשיך, מתבצעת הורדה של תוכן המדיה במקטעי נתונים (ניתן להגדיר את גודל המקטע).

קוד לדוגמה

אם ה-methods בספריות הספציפיות ל-API מכילות supportsMediaDownload במסמך Discovery, ואז Download ו-DownloadAsync שיטות נוחות זמינות בקטגוריית הבקשה. בשיטות האלה מתבצעת הורדה של נתוני המדיה לתוך Stream שתספקו. לדוגמה:
{
    // 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);
}