মিডিয়া আপলোড করুন
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
বেশ কিছু API পদ্ধতি নিয়মিত বডি ছাড়াও আপলোড মিডিয়া সমর্থন করে। সেক্ষেত্রে, আপলোড করার জন্য একটি অতিরিক্ত Stream
পেতে নিয়মিত অনুরোধের পদ্ধতিটি ওভারলোড করা হয়।
ওভারভিউ
আপনি যে Stream
আপলোড করতে চান তার জন্য, আপনার পুনরায় শুরু করা মিডিয়া আপলোড ব্যবহার করা উচিত, যা স্ট্রিমগুলিকে ছোট অংশে আপলোড করার অনুমতি দেয়। এটি বিশেষভাবে উপযোগী যদি আপনি বড় ফাইল স্থানান্তর করেন, এবং নেটওয়ার্ক বাধা বা অন্য কিছু ট্রান্সমিশন ব্যর্থতার সম্ভাবনা বেশি। এটি নেটওয়ার্ক ব্যর্থতার ক্ষেত্রে আপনার ব্যান্ডউইথের ব্যবহার কমাতে পারে কারণ আপনাকে শুরু থেকে বড় ফাইল আপলোডগুলি পুনরায় চালু করতে হবে না।
1.2.0-বিটা থেকে Google API .NET ক্লায়েন্ট লাইব্রেরিতে পুনঃসূচনাযোগ্য মিডিয়া আপলোড একটি বৈশিষ্ট্য। Google API-নির্দিষ্ট লাইব্রেরিতে এই বৈশিষ্ট্যটির সাথে ইন্টারঅ্যাক্ট করার সুবিধার পদ্ধতি রয়েছে।
পুনঃসূচনাযোগ্য মিডিয়া আপলোড প্রোটোকল বর্ণনা করা হয়েছে, উদাহরণস্বরূপ, ড্রাইভ API-এর জন্য মিডিয়া আপলোড পৃষ্ঠায় । আগ্রহের প্রধান শ্রেণী হল ResumableUpload
. এই বাস্তবায়নে, মিডিয়া বিষয়বস্তু খণ্ডে আপলোড করা হয়।
ডিফল্ট খণ্ডের আকার হল 10MB, তবে আপনি অনুরোধে ChunkSize
বৈশিষ্ট্যটি 256KB-এর যেকোনো একাধিকতে সেট করে এটি পরিবর্তন করতে পারেন। যদি একটি অনুরোধে সার্ভার ত্রুটির সম্মুখীন হয় তাহলে সূচকীয় ব্যাকঅফ নীতি সফলভাবে আপলোড করা হয়নি এমন বাইটগুলি পুনরায় পাঠাতে ব্যবহৃত হয়৷ ডিফল্টরূপে, প্রতিটি ক্লায়েন্ট অনুরোধের জন্য সূচকীয় ব্যাকঅফ সক্ষম করা হয়। BaseClientService.Initializer
এ DefaultExponentialBackOffPolicy
প্রপার্টি পরিবর্তন করে এবং/অথবা IConfigurableHttpClientInitializer
এর নিজস্ব বাস্তবায়নে HttpClientInitializer
প্রপার্টি সেট করে আপনি একটি নতুন পরিষেবা অবজেক্ট তৈরি করার সময় আপনি ডিফল্ট আচরণ পরিবর্তন করতে পারেন যা কিছু ব্যাকঅফ নীতি যোগ করে।
যে পদ্ধতিগুলি মিডিয়া আপলোড সমর্থন করে তা API-নির্দিষ্ট ডকুমেন্টেশনের জন্য রেফারেন্স ডকুমেন্টেশনে চিহ্নিত করা হয়। এই API পদ্ধতিগুলির জন্য, সুবিধার Upload
এবং UploadAsync
পদ্ধতি যোগ করা হয়। এই পদ্ধতিগুলি আপলোড করার জন্য একটি Stream
এবং এর বিষয়বস্তুর প্রকারকে পরামিতি হিসাবে গ্রহণ করে।
নিশ্চিত করুন যে আপনি যে স্ট্রিমটি আপলোড করছেন তার অবস্থানটি 0, অন্যথায় আপনি একটি ত্রুটি পাবেন, যেমন "System.InvalidOperationException: প্রদত্ত শিরোনাম পাওয়া যায়নি"।
মনে রাখবেন যে ফ্রেমওয়ার্কের HttpClient
ক্লাসের আচরণের কারণে, আপলোডের সময় শেষ হলে, একটি TaskCanceledException
নিক্ষেপ করা হয়। আপনি যদি এই ব্যতিক্রমটি দেখতে পান, আপনার পরিষেবা অবজেক্ট দ্বারা ব্যবহৃত ক্লায়েন্টে ম্যানুয়ালি Timeout
প্রপার্টি বাড়ানোর কথা বিবেচনা করুন।
নমুনা কোড
// Create the service using the client credentials.
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Application_Name"
});
using var uploadStream = System.IO.File.OpenRead("Local_File_Name");
// Create the File resource to upload.
Google.Apis.Drive.v3.Data.File driveFile = new Google.Apis.Drive.v3.Data.File
{
Name = "Drive_File_Name"
};
// Get the media upload request object.
FilesResource.CreateMediaUpload insertRequest = service.Files.Create(
driveFile, uploadStream, "image/jpeg");
// Add handlers which will be notified on progress changes and upload completion.
// Notification of progress changed will be invoked when the upload was started,
// on each upload chunk, and on success or failure.
insertRequest.ProgressChanged += Upload_ProgressChanged;
insertRequest.ResponseReceived += Upload_ResponseReceived;
await insertRequest.UploadAsync();
static void Upload_ProgressChanged(IUploadProgress progress) =>
Console.WriteLine(progress.Status + " " + progress.BytesSent);
static void Upload_ResponseReceived(Google.Apis.Drive.v3.Data.File file) =>
Console.WriteLine(file.Name + " was uploaded successfully");
অন্য কিছু উল্লেখ না করা থাকলে, এই পৃষ্ঠার কন্টেন্ট Creative Commons Attribution 4.0 License-এর অধীনে এবং কোডের নমুনাগুলি Apache 2.0 License-এর অধীনে লাইসেন্স প্রাপ্ত। আরও জানতে, Google Developers সাইট নীতি দেখুন। Java হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-24 UTC-তে শেষবার আপডেট করা হয়েছে।
[null,null,["2025-07-24 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["\u003cp\u003eSome API methods allow uploading media using resumable media upload, enabling the transfer of large files in smaller chunks, reducing bandwidth usage, and minimizing interruptions.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eResumableUpload\u003c/code\u003e class facilitates resumable media uploads with a default chunk size of 10MB, adjustable to multiples of 256KB, and includes exponential backoff for error handling.\u003c/p\u003e\n"],["\u003cp\u003eConvenience methods \u003ccode\u003eUpload\u003c/code\u003e and \u003ccode\u003eUploadAsync\u003c/code\u003e are available for API methods supporting media upload, accepting a stream and its content type as parameters, ensuring the stream's position is at 0 to avoid errors.\u003c/p\u003e\n"],["\u003cp\u003eConsider increasing the \u003ccode\u003eHttpClient\u003c/code\u003e timeout property to prevent \u003ccode\u003eTaskCanceledException\u003c/code\u003e during prolonged uploads, as demonstrated in the provided sample code.\u003c/p\u003e\n"],["\u003cp\u003eResumable media upload functionality is accessible through the Google API .NET client library, offering detailed documentation and progress tracking capabilities.\u003c/p\u003e\n"]]],[],null,["# Upload Media\n\nSeveral API methods support uploading media in addition to a regular body.\nIn that case, the regular request method is overloaded to get an additional\n`Stream` to upload.\n\nOverview\n--------\n\n\nFor any `Stream` you wish to upload, you should use resumable\nmedia upload, which allows streams to be uploaded in smaller chunks.\nThis is especially useful if you are transferring large files,\nand the likelihood of a network interruption or some other transmission\nfailure is high.\nIt can also reduce your bandwidth usage in the event of network failures\nbecause you don't have to restart large file uploads from the beginning.\n\nResumableMediaUpload\n--------------------\n\n\nResumable Media Upload has been a feature in the Google API .NET client library\nsince 1.2.0-beta.\nThe Google API-specific libraries contain convenience methods for\ninteracting with this feature.\n\n\nThe resumable media upload protocol is described, for example, on the\n[media upload page for the Drive API](https://developers.google.com/drive/manage-uploads#resumable).\nThe main class of interest is\n[`ResumableUpload`](https://googleapis.dev/dotnet/Google.Apis/latest/api/Google.Apis.Upload.ResumableUpload.html).\nIn this implementation, the media content is uploaded in chunks.\n\n\nThe default chunk size is 10MB, but you can change it by\nsetting the `ChunkSize` property on the request to any multiple of 256KB.\nIf a server error is encountered in a request then exponential backoff\npolicy is used to resend the bytes that were not successfully uploaded.\nBy default, exponential backoff is enabled for each client request.\nYou can change the default behavior when you construct\na new service object by changing the\n[`DefaultExponentialBackOffPolicy`](https://googleapis.dev/dotnet/Google.Apis/latest/api/Google.Apis.Services.BaseClientService.Initializer.html#Google_Apis_Services_BaseClientService_Initializer_DefaultExponentialBackOffPolicy) property on `BaseClientService.Initializer`\nand/or setting the\n[`HttpClientInitializer`](https://googleapis.dev/dotnet/Google.Apis/latest/api/Google.Apis.Services.BaseClientService.Initializer.html#Google_Apis_Services_BaseClientService_Initializer_HttpClientInitializer)\nproperty to your own implementation of `IConfigurableHttpClientInitializer`\nthat adds some backoff policy.\n\n\nThe methods that support media upload are identified\nin the reference documentation for the API-specific documentation.\nFor these API methods, convenience `Upload` and\n`UploadAsync` methods are added.\nThose methods take a `Stream` to upload and its content type as parameters.\n\n\nMake sure that the position of the stream you upload is 0, otherwise you will receive an error, such as\n\"System.InvalidOperationException: The given header was not found\".\n\n\nNote that due to the behavior of the framework's `HttpClient`\nclass, if the upload times out, a `TaskCanceledException` is thrown.\nIf you see this exception, consider manually increasing the `Timeout` property in\nthe client used by your service object.\n\nSample Code\n-----------\n\n```gdscript\n// Create the service using the client credentials.\nvar service = new DriveService(new BaseClientService.Initializer()\n{\n HttpClientInitializer = credential,\n ApplicationName = \"Application_Name\"\n});\n\nusing var uploadStream = System.IO.File.OpenRead(\"Local_File_Name\");\n\n// Create the File resource to upload.\nGoogle.Apis.Drive.v3.Data.File driveFile = new Google.Apis.Drive.v3.Data.File\n{\n Name = \"Drive_File_Name\"\n};\n// Get the media upload request object.\nFilesResource.CreateMediaUpload insertRequest = service.Files.Create(\n driveFile, uploadStream, \"image/jpeg\");\n\n// Add handlers which will be notified on progress changes and upload completion.\n// Notification of progress changed will be invoked when the upload was started,\n// on each upload chunk, and on success or failure.\ninsertRequest.ProgressChanged += Upload_ProgressChanged;\ninsertRequest.ResponseReceived += Upload_ResponseReceived;\n\nawait insertRequest.UploadAsync();\n\nstatic void Upload_ProgressChanged(IUploadProgress progress) =\u003e\n Console.WriteLine(progress.Status + \" \" + progress.BytesSent);\n\nstatic void Upload_ResponseReceived(Google.Apis.Drive.v3.Data.File file) =\u003e\n Console.WriteLine(file.Name + \" was uploaded successfully\");\n```"]]