تنزيل الوسائط
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تم توفير ميزة تنزيل الوسائط القابلة للاستئناف في مكتبة برامج .NET ضمن واجهة Google API منذ الإصدار التجريبي 1.4.0.
تحتوي المكتبات الخاصة بواجهة Google API على طرق ملائمة للتفاعل مع
هذه الميزة.
ويشبه بروتوكول تنزيل الوسائط القابلة للاستئناف بروتوكول تحميل الوسائط القابل للاستئناف.
على سبيل المثال، في
صفحة تحميل الوسائط لواجهة برمجة تطبيقات Drive.
الفئة الرئيسية من الاهتمام هي
MediaDownloader
في هذا التنفيذ لتنزيل الوسائط القابلة للاستئناف، يتم تنزيل محتوى الوسائط في أجزاء (حجم المجموعة قابل للتهيئة).
نموذج التعليمات البرمجية
إذا كانت الطرق في المكتبات الخاصة بواجهة برمجة التطبيقات تحتوي على
"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);
}
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThe Google API .NET client library supports resumable media download, allowing for the retrieval of large files in manageable chunks.\u003c/p\u003e\n"],["\u003cp\u003eResumable downloads function similarly to resumable uploads, offering a reliable mechanism for handling interruptions during data transfer.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can utilize the \u003ccode\u003eMediaDownloader\u003c/code\u003e class and convenient \u003ccode\u003eDownload\u003c/code\u003e/\u003ccode\u003eDownloadAsync\u003c/code\u003e methods within API-specific libraries to initiate and manage these downloads, providing a stream for the received data.\u003c/p\u003e\n"],["\u003cp\u003eThe download process is configurable, enabling customization of chunk size and progress tracking through events like \u003ccode\u003eProgressChanged\u003c/code\u003e for monitoring the transfer status.\u003c/p\u003e\n"]]],[],null,["# Download Media\n\nResumable media download has been a feature in the Google API .NET client library since 1.4.0-beta.\nThe Google API-specific libraries contain convenience methods for interacting with\nthis feature.\n\n\nThe resumable media download protocol is similar to the resumable media upload protocol which\nis described, for example, on the\n[media upload page for the Drive API](https://developers.google.com/drive/manage-uploads#resumable).\n\n\nThe main class of interest is\n[`MediaDownloader`](https://googleapis.dev/dotnet/Google.Apis/latest/api/Google.Apis.Download.MediaDownloader.html).\nIn this implementation of resumable media download, the media content is downloaded in chunks (chunk size is configurable).\n\nSample Code\n-----------\n\nIf 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: \n\n```gdscript\n{\n // Create the service using the client credentials.\n var storageService = new StorageService(new BaseClientService.Initializer()\n {\n HttpClientInitializer = credential,\n ApplicationName = \"APP_NAME_HERE\"\n });\n // Get the client request object for the bucket and desired object.\n var getRequest = storageService.Objects.Get(\"BUCKET_HERE\", \"OBJECT_HERE\");\n using (var fileStream = new System.IO.FileStream(\n \"FILE_PATH_HERE\",\n System.IO.FileMode.Create,\n System.IO.FileAccess.Write))\n {\n // Add a handler which will be notified on progress changes.\n // It will notify on each chunk download and when the\n // download is completed or failed.\n getRequest.MediaDownloader.ProgressChanged += Download_ProgressChanged;\n getRequest.Download(fileStream);\n }\n}\n\nstatic void Download_ProgressChanged(IDownloadProgress progress)\n{\n Console.WriteLine(progress.Status + \" \" + progress.BytesDownloaded);\n}\n```"]]