मीडिया डाउनलोड करें

फिर से शुरू किया जा सकने वाला मीडिया डाउनलोड, 1 .4.0-बीटा से Google API.NET क्लाइंट लाइब्रेरी की सुविधा है. Google API की खास लाइब्रेरी में, इस सुविधा का इस्तेमाल करने के आसान तरीके मौजूद हैं.

फिर से शुरू किया जा सकने वाला मीडिया डाउनलोड प्रोटोकॉल, फिर से शुरू किए जा सकने वाले मीडिया अपलोड प्रोटोकॉल के जैसा ही है. प्रोटोकॉल के बारे में फिर से बताया गया है. उदाहरण के लिए, Drive API के लिए मीडिया अपलोड पेज पर.

दिलचस्पी वाली मुख्य कैटगरी MediaDownloader है. फिर से शुरू किए जाने लायक मीडिया डाउनलोड के इस तरीके में, मीडिया कॉन्टेंट कई हिस्सों में डाउनलोड किया जाता है (इस तरह के हिस्से को कॉन्फ़िगर किया जा सकता है).

नमूना कोड

अगर एपीआई की खास लाइब्रेरी के तरीकों में, डिस्कवरी दस्तावेज़ में "supportsMediaDownload" पैरामीटर मौजूद है, तो इसका मतलब है कि 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);
}