ডাউনলোড করুন এবং ফাইল রপ্তানি করুন

গুগল ড্রাইভ এপিআই বিভিন্ন ধরনের ডাউনলোড এবং এক্সপোর্ট অ্যাকশন সমর্থন করে, যা নিম্নলিখিত সারণিতে তালিকাভুক্ত করা হলো:

ডাউনলোড অ্যাকশন
files.get মেথডের সাথে alt=media URL প্যারামিটার ব্যবহার করে ব্লব ফাইলের বিষয়বস্তু।
alt=media URL প্যারামিটার সহ revisions.get পদ্ধতি ব্যবহার করে পূর্ববর্তী সংস্করণের ব্লব ফাইলের বিষয়বস্তু।
webContentLink ফিল্ড ব্যবহার করে ব্রাউজারে ব্লব ফাইলের বিষয়বস্তু।
দীর্ঘ সময় ধরে চলা অপারেশনের সময় files.download মেথড ব্যবহার করে ব্লব ফাইলের কন্টেন্ট ডাউনলোড করা হয়। গুগল ভিডস ফাইল ডাউনলোড করার এটাই একমাত্র উপায়।
রপ্তানি কার্যক্রম
files.export পদ্ধতি ব্যবহার করে গুগল ওয়ার্কস্পেস ডকুমেন্টের কন্টেন্ট এমন একটি ফরম্যাটে রূপান্তর করুন যা আপনার অ্যাপ পরিচালনা করতে পারে।
exportLinks ফিল্ড ব্যবহার করে ব্রাউজারে গুগল ওয়ার্কস্পেস ডকুমেন্টের বিষয়বস্তু দেখুন।
exportLinks ফিল্ড ব্যবহার করে ব্রাউজারে গুগল ওয়ার্কস্পেস ডকুমেন্টের পূর্ববর্তী সংস্করণের কন্টেন্ট।
দীর্ঘ সময় ধরে চলা অপারেশন চলাকালীন files.download পদ্ধতি ব্যবহার করে গুগল ওয়ার্কস্পেস ডকুমেন্টের বিষয়বস্তু।

ফাইলের বিষয়বস্তু ডাউনলোড বা এক্সপোর্ট করার আগে, files রিসোর্সের capabilities.canDownload ফিল্ড ব্যবহার করে যাচাই করে নিন যে ব্যবহারকারীরা ফাইলটি ডাউনলোড করতে পারবে কি না।

এখানে উল্লেখিত ফাইল টাইপগুলোর, যার মধ্যে ব্লব এবং গুগল ওয়ার্কস্পেস ফাইলও অন্তর্ভুক্ত, বিবরণের জন্য ফাইলের প্রকারভেদ (File types ) দেখুন।

এই নির্দেশিকার বাকি অংশে এই ধরনের ডাউনলোড এবং এক্সপোর্ট কার্যক্রম সম্পাদনের জন্য বিস্তারিত নির্দেশাবলী দেওয়া হয়েছে।

ব্লব ফাইলের বিষয়বস্তু ডাউনলোড করুন

ড্রাইভে সংরক্ষিত একটি ব্লব ফাইল ডাউনলোড করতে, ডাউনলোড করার ফাইলের আইডি এবং alt=media URL প্যারামিটার সহ files.get মেথডটি ব্যবহার করুন। alt=media URL প্যারামিটারটি সার্ভারকে জানায় যে একটি বিকল্প প্রতিক্রিয়া বিন্যাস হিসাবে কন্টেন্ট ডাউনলোডের অনুরোধ করা হচ্ছে।

alt=media URL প্যারামিটারটি একটি সিস্টেম প্যারামিটার যা সমস্ত গুগল REST API-তে উপলব্ধ। আপনি যদি Drive API-এর জন্য কোনো ক্লায়েন্ট লাইব্রেরি ব্যবহার করেন, তাহলে আপনাকে এই প্যারামিটারটি স্পষ্টভাবে সেট করতে হবে না।

নিম্নলিখিত কোড নমুনাটিতে দেখানো হয়েছে কিভাবে Drive API ক্লায়েন্ট লাইব্রেরি ব্যবহার করে files.get মেথডের মাধ্যমে একটি ফাইল ডাউনলোড করতে হয়।

অ্যাপস স্ক্রিপ্ট

/**
 * Downloads a file from Drive.
 * @param {string} fileId The ID of the file to download.
 * @return {Blob} The file content as a Blob.
 */
function downloadFile(fileId) {
  var url = 'https://www.googleapis.com/drive/v3/files/' + fileId + '?alt=media';
  var response = UrlFetchApp.fetch(url, {
    headers: {
      'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()
    }
  });
  return response.getBlob();
}

জাভা

drive/snippets/drive_v3/src/main/java/DownloadFile.java
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;

/* Class to demonstrate use-case of drive's download file. */
public class DownloadFile {

  /**
   * Download a Document file in PDF format.
   *
   * @param realFileId file ID of any workspace document format file.
   * @return byte array stream if successful, {@code null} otherwise.
   * @throws IOException if service account credentials file not found.
   */
  public static ByteArrayOutputStream downloadFile(String realFileId) throws IOException {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
          guides on implementing OAuth2 for your application.*/
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
        .createScoped(Arrays.asList(DriveScopes.DRIVE_FILE));
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
        credentials);

    // Build a new authorized API client service.
    Drive service = new Drive.Builder(new NetHttpTransport(),
        GsonFactory.getDefaultInstance(),
        requestInitializer)
        .setApplicationName("Drive samples")
        .build();

    try {
      OutputStream outputStream = new ByteArrayOutputStream();

      service.files().get(realFileId)
          .executeMediaAndDownloadTo(outputStream);

      return (ByteArrayOutputStream) outputStream;
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      System.err.println("Unable to move file: " + e.getDetails());
      throw e;
    }
  }
}

পাইথন

drive/snippets/drive-v3/file_snippet/download_file.py
import io

import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from googleapiclient.http import MediaIoBaseDownload


def download_file(real_file_id):
  """Downloads a file
  Args:
      real_file_id: ID of the file to download
  Returns : IO object with location.

  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()

  try:
    # create drive api client
    service = build("drive", "v3", credentials=creds)

    file_id = real_file_id

    # pylint: disable=maybe-no-member
    request = service.files().get_media(fileId=file_id)
    file = io.BytesIO()
    downloader = MediaIoBaseDownload(file, request)
    done = False
    while done is False:
      status, done = downloader.next_chunk()
      print(f"Download {int(status.progress() * 100)}.")

  except HttpError as error:
    print(f"An error occurred: {error}")
    file = None

  return file.getvalue()


if __name__ == "__main__":
  download_file(real_file_id="1KuPmvGq8yoYgbfW74OENMCB5H0n_2Jm9")

নোড.জেএস

drive/snippets/drive_v3/file_snippets/download_file.js
import {GoogleAuth} from 'google-auth-library';
import {google} from 'googleapis';

/**
 * Downloads a file from Google Drive.
 * @param {string} fileId The ID of the file to download.
 * @return {Promise<number>} The status of the download.
 */
async function downloadFile(fileId) {
  // Authenticate with Google and get an authorized client.
  // TODO (developer): Use an appropriate auth mechanism for your app.
  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/drive',
  });

  // Create a new Drive API client (v3).
  const service = google.drive({version: 'v3', auth});

  // Download the file.
  const file = await service.files.get({
    fileId,
    alt: 'media',
  });

  // Print the status of the download.
  console.log(file.status);
  return file.status;
}

পিএইচপি

drive/snippets/drive_v3/src/DriveDownloadFile.php
<?php
use Google\Client;
use Google\Service\Drive;
function downloadFile()
 {
    try {

      $client = new Client();
      $client->useApplicationDefaultCredentials();
      $client->addScope(Drive::DRIVE);
      $driveService = new Drive($client);
      $realFileId = readline("Enter File Id: ");
      $fileId = '0BwwA4oUTeiV1UVNwOHItT0xfa2M';
      $fileId = $realFileId;
      $response = $driveService->files->get($fileId, array(
          'alt' => 'media'));
      $content = $response->getBody()->getContents();
      return $content;

    } catch(Exception $e) {
      echo "Error Message: ".$e;
    }

}

.NET

drive/snippets/drive_v3/DriveV3Snippets/downloadFile.cs
using Google.Apis.Auth.OAuth2;
using Google.Apis.Download;
using Google.Apis.Drive.v3;
using Google.Apis.Services;

namespace DriveV3Snippets
{
    // Class to demonstrate use-case of drive's download file.
    public class DownloadFile
    {
        /// <summary>
        /// Download a Document file in PDF format.
        /// </summary>
        /// <param name="fileId">file ID of any workspace document format file.</param>
        /// <returns>byte array stream if successful, null otherwise.</returns>
        public static MemoryStream DriveDownloadFile(string fileId)
        {
            try
            {
                /* Load pre-authorized user credentials from the environment.
                 TODO(developer) - See https://developers.google.com/identity for 
                 guides on implementing OAuth2 for your application. */
                GoogleCredential credential = GoogleCredential
                    .GetApplicationDefault()
                    .CreateScoped(DriveService.Scope.Drive);

                // Create Drive API service.
                var service = new DriveService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "Drive API Snippets"
                });

                var request = service.Files.Get(fileId);
                var stream = new MemoryStream();

                // 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.
                request.MediaDownloader.ProgressChanged +=
                    progress =>
                    {
                        switch (progress.Status)
                        {
                            case DownloadStatus.Downloading:
                            {
                                Console.WriteLine(progress.BytesDownloaded);
                                break;
                            }
                            case DownloadStatus.Completed:
                            {
                                Console.WriteLine("Download complete.");
                                break;
                            }
                            case DownloadStatus.Failed:
                            {
                                Console.WriteLine("Download failed.");
                                break;
                            }
                        }
                    };
                request.Download(stream);

                return stream;
            }
            catch (Exception e)
            {
                // TODO(developer) - handle error appropriately
                if (e is AggregateException)
                {
                    Console.WriteLine("Credential Not found");
                }
                else
                {
                    throw;
                }
            }
            return null;
        }
    }
}

এই কোড নমুনাটিতে একটি লাইব্রেরি পদ্ধতি ব্যবহার করা হয়েছে, যা মূল HTTP অনুরোধে alt=media URL প্যারামিটারটি যোগ করে।

আপনার অ্যাপ থেকে শুরু করা ফাইল ডাউনলোড অবশ্যই এমন একটি স্কোপ দিয়ে অনুমোদিত হতে হবে যা ফাইলের বিষয়বস্তু পড়ার অ্যাক্সেস দেয়। উদাহরণস্বরূপ, drive.readonly.metadata স্কোপ ব্যবহারকারী কোনো অ্যাপ ফাইলের বিষয়বস্তু ডাউনলোড করার জন্য অনুমোদিত নয়। এই কোড স্যাম্পলটি সীমাবদ্ধ “drive” ফাইল স্কোপ ব্যবহার করে, যা ব্যবহারকারীদের আপনার সমস্ত ড্রাইভ ফাইল দেখতে এবং পরিচালনা করতে দেয়। ড্রাইভ স্কোপ সম্পর্কে আরও জানতে, “Choose Google Drive API scopes” দেখুন।

যেসব ব্যবহারকারীর owner অনুমতি (আমার ড্রাইভ ফাইলের জন্য) অথবা organizer অনুমতি (শেয়ার করা ড্রাইভ ফাইলের জন্য) আছে, তারা DownloadRestrictionsMetadata অবজেক্টের মাধ্যমে ডাউনলোড সীমাবদ্ধ করতে পারেন। আরও তথ্যের জন্য, ব্যবহারকারীদের আপনার ফাইল ডাউনলোড, প্রিন্ট বা কপি করা থেকে বিরত রাখুন দেখুন।

আপত্তিকর হিসেবে চিহ্নিত ফাইল (যেমন ক্ষতিকারক সফটওয়্যার) শুধুমাত্র ফাইলের মালিকই ডাউনলোড করতে পারেন। এছাড়াও, ব্যবহারকারী যে সম্ভাব্য অনাকাঙ্ক্ষিত সফটওয়্যার বা অন্যান্য আপত্তিকর ফাইল ডাউনলোড করার ঝুঁকি স্বীকার করেছেন, তা বোঝানোর জন্য acknowledgeAbuse=true এই ` get কোয়েরি প্যারামিটারটি অবশ্যই অন্তর্ভুক্ত করতে হবে। এই কোয়েরি প্যারামিটারটি ব্যবহার করার আগে আপনার অ্যাপ্লিকেশনটির উচিত ব্যবহারকারীকে ইন্টারেক্টিভভাবে সতর্ক করা।

আংশিক ডাউনলোড

আংশিক ডাউনলোড বলতে কোনো ফাইলের কেবল একটি নির্দিষ্ট অংশ ডাউনলোড করাকে বোঝায়। আপনি Range হেডারের সাথে একটি বাইট রেঞ্জ ব্যবহার করে ফাইলের যে অংশটি ডাউনলোড করতে চান তা নির্দিষ্ট করতে পারেন। উদাহরণস্বরূপ:

Range: bytes=500-999

পূর্ববর্তী সংস্করণে ব্লব ফাইলের বিষয়বস্তু ডাউনলোড করুন

আপনি শুধুমাত্র "চিরকালের জন্য রাখুন" হিসেবে চিহ্নিত ব্লব ফাইলের কন্টেন্ট রিভিশনগুলোই ডাউনলোড করতে পারবেন। আপনি যদি কোনো রিভিশন ডাউনলোড করতে চান, তবে প্রথমে সেটিকে "চিরকালের জন্য রাখুন" হিসেবে সেট করুন। আরও তথ্যের জন্য, স্বয়ংক্রিয়ভাবে মুছে যাওয়া থেকে রক্ষা করার জন্য রিভিশন নির্দিষ্ট করুন দেখুন।

ব্লব ফাইলের কন্টেন্ট পূর্ববর্তী সংস্করণে ডাউনলোড করতে, ডাউনলোড করার ফাইলের আইডি, রিভিশনের আইডি এবং alt=media URL প্যারামিটার সহ revisions.get মেথডটি ব্যবহার করুন। alt=media URL প্যারামিটারটি সার্ভারকে জানায় যে একটি বিকল্প রেসপন্স ফরম্যাট হিসেবে কন্টেন্ট ডাউনলোডের অনুরোধ করা হচ্ছে। files.get এর মতোই, revisions.get মেথডটিও ঐচ্ছিক কোয়েরি প্যারামিটার acknowledgeAbuse এবং Range হেডার গ্রহণ করে। আরও তথ্যের জন্য, Manage long-running operations দেখুন।

অনুরোধ প্রোটোকলটি এখানে দেখানো হলো।

GET https://www.googleapis.com/drive/v3/files/{FILE_ID}/revisions/{REVISION_ID}?alt=media

ব্রাউজারে ব্লব ফাইলের বিষয়বস্তু ডাউনলোড করুন

এপিআই (API)-এর মাধ্যমে ডাউনলোড না করে, ব্রাউজারের মধ্যে ড্রাইভে সংরক্ষিত ব্লব ফাইলের কন্টেন্ট ডাউনলোড করতে হলে files রিসোর্সের ` webContentLink ফিল্ডটি ব্যবহার করুন। যদি ব্যবহারকারীর ফাইলটি ডাউনলোড করার অ্যাক্সেস থাকে, তাহলে ফাইলটি এবং এর ভেতরের কন্টেন্ট ডাউনলোড করার জন্য একটি লিঙ্ক ফেরত দেওয়া হয়। আপনি ব্যবহারকারীকে এই ইউআরএল-এ রিডাইরেক্ট করতে পারেন, অথবা এটিকে একটি ক্লিকযোগ্য লিঙ্ক হিসেবে প্রদান করতে পারেন।

দীর্ঘ সময় ধরে চলা অপারেশন চলাকালীন ব্লব ফাইলের বিষয়বস্তু ডাউনলোড করুন

দীর্ঘ সময় ধরে চলা অপারেশনের সময় ব্লব ফাইলের বিষয়বস্তু ডাউনলোড করতে, ডাউনলোড করার ফাইলের আইডি সহ files.download মেথডটি ব্যবহার করুন। আপনি চাইলে রিভিশনের আইডি-ও সেট করতে পারেন।

গুগল ভিডস ফাইল ডাউনলোড করার এটিই একমাত্র উপায়। আপনি যদি গুগল ভিডস ফাইল এক্সপোর্ট করার চেষ্টা করেন, তাহলে একটি fileNotExportable ত্রুটি পাবেন। আরও তথ্যের জন্য, `Manage long-running operations` দেখুন।

গুগল ওয়ার্কস্পেস ডকুমেন্টের বিষয়বস্তু রপ্তানি করুন

গুগল ওয়ার্কস্পেস ডকুমেন্টের বাইট কন্টেন্ট এক্সপোর্ট করতে, এক্সপোর্ট করার ফাইলের আইডি এবং সঠিক MIME টাইপ সহ files.export মেথডটি ব্যবহার করুন। এক্সপোর্ট করা কন্টেন্টের সীমা ১০ মেগাবাইট।

নিম্নলিখিত কোড নমুনাটি দেখায় কিভাবে Drive API ক্লায়েন্ট লাইব্রেরি ব্যবহার করে files.export পদ্ধতির মাধ্যমে একটি Google Workspace ডকুমেন্টকে PDF ফরম্যাটে এক্সপোর্ট করা যায়:

অ্যাপস স্ক্রিপ্ট

/**
 * Exports a Google Workspace document.
 * @param {string} fileId The ID of the file to export.
 * @param {string} mimeType The MIME type to export to.
 * @return {Blob} The exported content as a Blob.
 */
function exportPdf(fileId, mimeType) {
  var url = 'https://www.googleapis.com/drive/v3/files/' + fileId + '/export?mimeType=' + encodeURIComponent(mimeType);
  var response = UrlFetchApp.fetch(url, {
    headers: {
      'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()
    }
  });
  return response.getBlob();
}

জাভা

drive/snippets/drive_v3/src/main/java/ExportPdf.java
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;

/* Class to demonstrate use-case of drive's export pdf. */
public class ExportPdf {

  /**
   * Download a Document file in PDF format.
   *
   * @param realFileId file ID of any workspace document format file.
   * @return byte array stream if successful, {@code null} otherwise.
   * @throws IOException if service account credentials file not found.
   */
  public static ByteArrayOutputStream exportPdf(String realFileId) throws IOException {
    // Load pre-authorized user credentials from the environment.
    // TODO(developer) - See https://developers.google.com/identity for
    // guides on implementing OAuth2 for your application.
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
        .createScoped(Arrays.asList(DriveScopes.DRIVE_FILE));
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
        credentials);

    // Build a new authorized API client service.
    Drive service = new Drive.Builder(new NetHttpTransport(),
        GsonFactory.getDefaultInstance(),
        requestInitializer)
        .setApplicationName("Drive samples")
        .build();

    OutputStream outputStream = new ByteArrayOutputStream();
    try {
      service.files().export(realFileId, "application/pdf")
          .executeMediaAndDownloadTo(outputStream);

      return (ByteArrayOutputStream) outputStream;
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      System.err.println("Unable to export file: " + e.getDetails());
      throw e;
    }
  }
}

পাইথন

drive/snippets/drive-v3/file_snippet/export_pdf.py
import io

import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from googleapiclient.http import MediaIoBaseDownload


def export_pdf(real_file_id):
  """Download a Document file in PDF format.
  Args:
      real_file_id : file ID of any workspace document format file
  Returns : IO object with location

  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()

  try:
    # create drive api client
    service = build("drive", "v3", credentials=creds)

    file_id = real_file_id

    # pylint: disable=maybe-no-member
    request = service.files().export_media(
        fileId=file_id, mimeType="application/pdf"
    )
    file = io.BytesIO()
    downloader = MediaIoBaseDownload(file, request)
    done = False
    while done is False:
      status, done = downloader.next_chunk()
      print(f"Download {int(status.progress() * 100)}.")

  except HttpError as error:
    print(f"An error occurred: {error}")
    file = None

  return file.getvalue()


if __name__ == "__main__":
  export_pdf(real_file_id="1zbp8wAyuImX91Jt9mI-CAX_1TqkBLDEDcr2WeXBbKUY")

নোড.জেএস

drive/snippets/drive_v3/file_snippets/export_pdf.js
import {GoogleAuth} from 'google-auth-library';
import {google} from 'googleapis';

/**
 * Exports a Google Doc as a PDF.
 * @param {string} fileId The ID of the file to export.
 * @return {Promise<number>} The status of the export request.
 */
async function exportPdf(fileId) {
  // Authenticate with Google and get an authorized client.
  // TODO (developer): Use an appropriate auth mechanism for your app.
  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/drive',
  });

  // Create a new Drive API client (v3).
  const service = google.drive({version: 'v3', auth});

  // Export the file as a PDF.
  const result = await service.files.export({
    fileId,
    mimeType: 'application/pdf',
  });

  // Print the status of the export.
  console.log(result.status);
  return result.status;
}

পিএইচপি

drive/snippets/drive_v3/src/DriveExportPdf.php
<?php
use Google\Client;
use Google\Service\Drive;
function exportPdf()
{
    try {
        $client = new Client();
        $client->useApplicationDefaultCredentials();
        $client->addScope(Drive::DRIVE);
        $driveService = new Drive($client);
        $realFileId = readline("Enter File Id: ");
        $fileId = '1ZdR3L3qP4Bkq8noWLJHSr_iBau0DNT4Kli4SxNc2YEo';
        $fileId = $realFileId;
        $response = $driveService->files->export($fileId, 'application/pdf', array(
            'alt' => 'media'));
        $content = $response->getBody()->getContents();
        return $content;

    }  catch(Exception $e) {
         echo "Error Message: ".$e;
    }

}

.NET

drive/snippets/drive_v3/DriveV3Snippets/ExportPdf.cs
using Google.Apis.Auth.OAuth2;
using Google.Apis.Download;
using Google.Apis.Drive.v3;
using Google.Apis.Services;

namespace DriveV3Snippets
{
    // Class to demonstrate use of Drive export pdf
    public class ExportPdf
    {
        /// <summary>
        /// Download a Document file in PDF format.
        /// </summary>
        /// <param name="fileId">Id of the file.</param>
        /// <returns>Byte array stream if successful, null otherwise</returns>
        public static MemoryStream DriveExportPdf(string fileId)
        {
            try
            {
                /* Load pre-authorized user credentials from the environment.
                 TODO(developer) - See https://developers.google.com/identity for 
                 guides on implementing OAuth2 for your application. */
                GoogleCredential credential = GoogleCredential.GetApplicationDefault()
                    .CreateScoped(DriveService.Scope.Drive);

                // Create Drive API service.
                var service = new DriveService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "Drive API Snippets"
                });

                var request = service.Files.Export(fileId, "application/pdf");
                var stream = new MemoryStream();
                // 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.
                request.MediaDownloader.ProgressChanged +=
                    progress =>
                    {
                        switch (progress.Status)
                        {
                            case DownloadStatus.Downloading:
                            {
                                Console.WriteLine(progress.BytesDownloaded);
                                break;
                            }
                            case DownloadStatus.Completed:
                            {
                                Console.WriteLine("Download complete.");
                                break;
                            }
                            case DownloadStatus.Failed:
                            {
                                Console.WriteLine("Download failed.");
                                break;
                            }
                        }
                    };
                request.Download(stream);
                return stream;
            }
            catch (Exception e)
            {
                // TODO(developer) - handle error appropriately
                if (e is AggregateException)
                {
                    Console.WriteLine("Credential Not found");
                }
                else
                {
                    throw;
                }
            }
            return null;
        }
    }
}

এই কোড স্যাম্পলটি সীমাবদ্ধ drive স্কোপ ব্যবহার করে, যা ব্যবহারকারীদের আপনার ড্রাইভের সমস্ত ফাইল দেখতে ও পরিচালনা করতে দেয়। ড্রাইভ স্কোপ সম্পর্কে আরও জানতে, “গুগল ড্রাইভ এপিআই স্কোপ নির্বাচন করুন” দেখুন।

কোড স্যাম্পলটিতে এক্সপোর্ট MIME টাইপ হিসেবে application/pdf ঘোষণা করা হয়েছে। প্রতিটি Google Workspace ডকুমেন্টের জন্য সমর্থিত সমস্ত এক্সপোর্ট MIME টাইপের সম্পূর্ণ তালিকার জন্য, “Export MIME types for Google Workspace documents” দেখুন।

ব্রাউজারে গুগল ওয়ার্কস্পেস ডকুমেন্টের বিষয়বস্তু এক্সপোর্ট করুন

ব্রাউজারের মধ্যে গুগল ওয়ার্কস্পেস ডকুমেন্টের বিষয়বস্তু এক্সপোর্ট করতে, files রিসোর্সের exportLinks ফিল্ডটি ব্যবহার করুন। ডকুমেন্টের ধরনের ওপর নির্ভর করে, উপলব্ধ প্রতিটি MIME টাইপের জন্য ফাইল এবং এর বিষয়বস্তু ডাউনলোড করার একটি লিঙ্ক ফেরত দেওয়া হয়। আপনি ব্যবহারকারীকে একটি URL-এ রিডাইরেক্ট করতে পারেন, অথবা এটিকে একটি ক্লিকযোগ্য লিঙ্ক হিসেবে প্রদান করতে পারেন।

ব্রাউজারে গুগল ওয়ার্কস্পেস ডকুমেন্টের বিষয়বস্তু পূর্ববর্তী সংস্করণে এক্সপোর্ট করুন

ব্রাউজারের মধ্যে গুগল ওয়ার্কস্পেস ডকুমেন্টের কন্টেন্ট পূর্ববর্তী কোনো সংস্করণে এক্সপোর্ট করতে, ডাউনলোড করার ফাইলের আইডি এবং রিভিশনের আইডি সহ revisions.get মেথডটি ব্যবহার করুন। এটি একটি এক্সপোর্ট লিঙ্ক তৈরি করবে যেখান থেকে আপনি ডাউনলোড করতে পারবেন। যদি ব্যবহারকারীর ফাইলটি ডাউনলোড করার অ্যাক্সেস থাকে, তাহলে ফাইল এবং এর কন্টেন্ট ডাউনলোড করার জন্য একটি লিঙ্ক ফেরত দেওয়া হয়। আপনি ব্যবহারকারীকে এই URL-এ রিডাইরেক্ট করতে পারেন, অথবা এটিকে একটি ক্লিকযোগ্য লিঙ্ক হিসেবে প্রদান করতে পারেন।

দীর্ঘ সময় ধরে চলা অপারেশন চলাকালীন গুগল ওয়ার্কস্পেস ডকুমেন্টের বিষয়বস্তু রপ্তানি করুন

দীর্ঘ সময় ধরে চলা অপারেশন চলাকালীন গুগল ওয়ার্কস্পেস ডকুমেন্টের বিষয়বস্তু এক্সপোর্ট করতে, ডাউনলোড করার ফাইলের আইডি এবং রিভিশনের আইডি সহ files.download মেথডটি ব্যবহার করুন। আরও তথ্যের জন্য, দীর্ঘ সময় ধরে চলা অপারেশন পরিচালনা দেখুন।

ফাইল শেয়ার করার পদ্ধতি সীমিত করুন