फ़ाइल के कॉन्टेंट को सुरक्षित रखना

Google Drive API, फ़ाइल में बदलाव को रोकने के कई तरीकों के साथ काम करता है. इनमें ये तरीके शामिल हैं के कॉन्टेंट पर पाबंदी लगाना और डाउनलोड, प्रिंट या कॉपी करने के विकल्प पर रोक लगाना फ़ाइलें.

Drive में मौजूद कॉन्टेंट पर पाबंदियां लगाने की सुविधा की मदद से, फ़ाइलों को रीड ओनली ऐक्सेस देना

उपयोगकर्ताओं को: ये काम किए जा सकते हैं:

  • टाइटल में बदलाव किया जा रहा है
  • कॉन्टेंट में बदलाव करना
  • संशोधन अपलोड करना
  • टिप्पणियां जोड़ना या उनमें बदलाव करना

कॉन्टेंट पर पाबंदियां लगाने का तरीका आइटम को बदले बिना, Drive में मौजूद आइटम को सिर्फ़ पढ़ने के लिए सेट करें अनुमतियां ऐक्सेस करने के लिए. इसका मतलब है कि पाबंदी नहीं है. उपयोगकर्ता फ़ाइल के कॉन्टेंट में बदलाव नहीं कर सकते. हालांकि, अन्य अब भी ऐक्सेस लेवल के आधार पर कार्रवाइयां करने की अनुमति है (उदाहरण के लिए, उपयोगकर्ता के पास बदलाव करने का ऐक्सेस, अब भी किसी आइटम को एक जगह से दूसरी जगह ले जा सकता है या उसकी शेयर करने की सेटिंग में बदलाव कर सकता है).

Drive में किसी फ़ाइल पर कॉन्टेंट पर पाबंदी लगाने या हटाने के लिए, उपयोगकर्ता से संबंधित होना चाहिए अनुमतियां. इसमें मौजूद किसी फ़ाइल या फ़ोल्डर के लिए मेरी ड्राइव या शेयर की गई ड्राइव को capabilities.canModifyEditorContentRestriction, आपके पास role=writer होना चाहिए असाइन किया गया है. मेरी ड्राइव या शेयर की गई ड्राइव में मौजूद किसी फ़ाइल या फ़ोल्डर के लिए, ownerRestricted कॉन्टेंट पर पाबंदी है, तो फ़ाइल का मालिकाना हक आपके पास होना चाहिए या role=organizer. जिस आइटम पर कॉन्टेंट पर पाबंदी लगी है उसे देखने के लिए, उपयोगकर्ताओं के पास ये चीज़ें होनी चाहिए role=reader या उससे ज़्यादा. भूमिकाओं की पूरी सूची के लिए, भूमिकाएं और अनुमतियां हैं. किसी फ़ाइल की अनुमतियां बदलने के लिए, देखें अनुमतियां बदलें.

contentRestrictions.readOnly बूलियन फ़ील्ड का इस्तेमाल सेट करने के लिए files संसाधन कॉन्टेंट पर पाबंदी लगा सकते हैं. ध्यान दें कि किसी आइटम पर कॉन्टेंट के लिए पाबंदी सेट करना मौजूदा यूआरएल की जगह ले लेता है.

कॉन्टेंट पर पाबंदियां लगाने से जुड़ी स्थितियां

Drive में मौजूद किसी आइटम पर कॉन्टेंट पर पाबंदी लगाने से उपयोगकर्ताओं को यह पता चलता है कि कॉन्टेंट में बदलाव नहीं किया जाना चाहिए. ऐसा नीचे दी गई कुछ वजहों से हो सकता है:

  • समीक्षा या ऑडिट की अवधि के दौरान, साथ मिलकर काम करने वाले दस्तावेज़ पर काम को रोकना.
  • किसी आइटम को फ़ाइनल स्थिति पर सेट करना, जैसे कि मंज़ूरी दी गई.
  • संवेदनशील मीटिंग के दौरान बदलाव करने से रोकना.
  • ऑटोमेटेड सिस्टम (कार्रवाइयों को अपने-आप पूरा करने वाले सिस्टम) से मैनेज किए जाने वाले वर्कफ़्लो में, बाहरी बदलावों को रोकना.
  • Google Apps Script और Google Workspace ऐड-ऑन से बदलाव करने पर पाबंदी लगाना.
  • किसी दस्तावेज़ में गलती से होने वाले बदलाव से बचना.

ध्यान दें कि कॉन्टेंट पर पाबंदियां लगाने से कॉन्टेंट को मैनेज करने में मदद मिल सकती है. हालांकि, ऐसा नहीं है इसका मकसद, ज़रूरी अनुमतियों वाले उपयोगकर्ताओं को आइटम. इसके अलावा, यह ऐसा रिकॉर्ड नहीं बनाया जा सकता जिसमें बदलाव न किया जा सके. Drive के कॉन्टेंट पर लगी पाबंदियों में बदलाव किया जा सकता है. इसलिए, कॉन्टेंट पर पाबंदी लगाई जा सकती है इस बात की गारंटी नहीं है कि आइटम कभी नहीं बदलेगा.

कॉन्टेंट पर पाबंदियों वाली फ़ाइलें मैनेज करना

Google Docs, Google Sheets, और Google Slides के साथ-साथ अन्य सभी फ़ाइलें, कॉन्टेंट पर पाबंदियां हो सकती हैं.

किसी आइटम पर पाबंदी लगने से, उसके टाइटल और कॉन्टेंट में बदलाव नहीं होता, शामिल हैं:

  • टिप्पणियां और सुझाव (Docs, Sheets, Slides और बाइनरी फ़ाइलें)
  • बाइनरी फ़ाइल में बदलाव
  • Docs में टेक्स्ट और फ़ॉर्मैटिंग
  • Sheets के लेआउट, Sheets के लेआउट, और Sheets में इंस्टेंस
  • Slides में मौजूद पूरा कॉन्टेंट और किताबों का क्रम और संख्या स्लाइड

कुछ फ़ाइल टाइप में कॉन्टेंट पर पाबंदी नहीं लगाई जा सकती. यहां इसके कुछ उदाहरण दिए गए हैं:

कॉन्टेंट पर पाबंदी लगाना

फ़ाइल के कॉन्टेंट पर पाबंदी लगाने के लिए, files.update तरीका contentRestrictions.readOnly फ़ील्ड को true पर सेट किया गया. इसके लिए एक वैकल्पिक reason जोड़ें आपको उस पर पाबंदी क्यों लगानी है. जैसे, "समझौता पूरा किया जा चुका है." नीचे दिए गए कोड सैंपल, कॉन्टेंट पर पाबंदी जोड़ने का तरीका बताता है:

Java

File updatedFile =
  new File()
      .setContentRestrictions(
          ImmutableList.of(new ContentRestriction().setReadOnly(true).setReason("Finalized contract."));

File response = driveService.files().update("FILE_ID", updatedFile).setFields("contentRestrictions").execute();

Python

content_restriction = {'readOnly': True, 'reason':'Finalized contract.'}

response = drive_service.files().update(fileId="FILE_ID", body = {'contentRestrictions' : [content_restriction]}, fields = "contentRestrictions").execute();

Node.js

/**
* Set a content restriction on a file.
* @return{obj} updated file
**/
async function addContentRestriction() {
  // Get credentials and build service
  // TODO (developer) - Use appropriate auth mechanism for your app

  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});
  const service = google.drive({version: 'v3', auth});
  const contentRestriction = {
    'readOnly': True,
    'reason': 'Finalized contract.',
  };
  const updatedFile = {
    'contentRestrictions': [contentRestriction],
  };
  try {
    const response = await service.files.update({
      fileId: 'FILE_ID',
      resource: updatedFile,
      fields: 'contentRestrictions',
    });
    return response;
  } catch (err) {
    // TODO (developer) - Handle error
    throw err;
  }
}

FILE_ID को उस फ़ाइल के fileId से बदलें जिसे आपको जोड़ना है बदलें.

सैंपल कोड को चलाने पर, फ़ाइल में कॉन्टेंट पर पाबंदी लगी होती है और एक लॉक सिंबल होता है (), इसमें फ़ाइल नाम के बगल में दिखता है Google डिस्क यूज़र इंटरफ़ेस (यूज़र इंटरफ़ेस). कॉन्टेंट बनाने फ़ाइल अब सिर्फ़ पढ़ने के लिए है.

Drive में मौजूद फ़ाइलों की सूची में मौजूद, कॉन्टेंट पर पाबंदी वाली फ़ाइल.
पहली इमेज. Drive में मौजूद फ़ाइलों की सूची में मौजूद, कॉन्टेंट पर पाबंदी वाली फ़ाइल.

कॉन्टेंट पर लगी पाबंदी हटाना

फ़ाइल के कॉन्टेंट पर लगी पाबंदी को हटाने के लिए, files.update तरीका इस्तेमाल करें. इसके लिए, contentRestrictions.readOnly फ़ील्ड को false पर सेट किया गया. यहां दिया गया कोड सैंपल कॉन्टेंट पर लगी पाबंदी को हटाने का तरीका दिखाया गया है:

Java

File updatedFile =
new File()
    .setContentRestrictions(
        ImmutableList.of(new ContentRestriction().setReadOnly(false));

File response = driveService.files().update("FILE_ID", updatedFile).setFields("contentRestrictions").execute();

Python

content_restriction = {'readOnly': False}

response = drive_service.files().update(fileId="FILE_ID", body = {'contentRestrictions' : [content_restriction]}, fields = "contentRestrictions").execute();

Node.js

/**
* Remove a content restriction on a file.
* @return{obj} updated file
**/
async function removeContentRestriction() {
  // Get credentials and build service
  // TODO (developer) - Use appropriate auth mechanism for your app

  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});
  const service = google.drive({version: 'v3', auth});
  const contentRestriction = {
    'readOnly': False,
  };
  const updatedFile = {
    'contentRestrictions': [contentRestriction],
  };
  try {
    const response = await service.files.update({
      fileId: 'FILE_ID',
      resource: updatedFile,
      fields: 'contentRestrictions',
    });
    return response;
  } catch (err) {
    // TODO (developer) - Handle error
    throw err;
  }
}

FILE_ID को उस फ़ाइल के fileId से बदलें जिसे आपको जोड़ना है बदलें.

सैंपल कोड चलाने पर, फ़ाइल के कॉन्टेंट पर पाबंदी नहीं रहती.

कॉन्टेंट पर लगी पाबंदी को हटाने के लिए, Drive के यूज़र इंटरफ़ेस (यूआई) का इस्तेमाल किया जा सकता है और कॉन्टेंट में बदलाव करने की अनुमति दें (बशर्ते आपके पास सही अनुमतियां हों). दो विकल्प मौजूद हैं:

  1. Drive में, कॉन्टेंट पर पाबंदी वाली फ़ाइल पर राइट क्लिक करें और अनलॉक करें पर क्लिक करें.

    Drive की फ़ाइलों की सूची में से किसी फ़ाइल पर लगी पाबंदी को हटाएं.
    दूसरी इमेज. Drive की फ़ाइलों की सूची में से किसी फ़ाइल पर लगी पाबंदी को हटाएं.
  2. कॉन्टेंट पर पाबंदी वाली फ़ाइल खोलें और (लॉक मोड) पर क्लिक करें > फ़ाइल अनलॉक करें.

    किसी दस्तावेज़ में से फ़ाइल के कॉन्टेंट पर लगी पाबंदी हटाएं.
    तीसरी इमेज. किसी दस्तावेज़ में से फ़ाइल पर लगी पाबंदी को हटाएं.

देखें कि कॉन्टेंट पर पाबंदी लगी है या नहीं

कॉन्टेंट पर पाबंदी है या नहीं, यह जानने के लिए files.get तरीका contentRestrictions फ़ील्ड दिखाया गया. नीचे दिया गया कोड सैंपल, कॉन्टेंट पर पाबंदी की स्थिति देखें:

Java

File response = driveService.files().get("FILE_ID").setFields("contentRestrictions").execute();

Python

response = drive_service.files().get(fileId="FILE_ID", fields = "contentRestrictions").execute();

Node.js

/**
* Get content restrictions on a file.
* @return{obj} updated file
**/
async function fetchContentRestrictions() {
  // Get credentials and build service
  // TODO (developer) - Use appropriate auth mechanism for your app

  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});
  const service = google.drive({version: 'v3', auth});
  try {
    const response = await service.files.get({
      fileId: 'FILE_ID',
      fields: 'contentRestrictions',
    });
    return response;
  } catch (err) {
    // TODO (developer) - Handle error
    throw err;
  }
}

FILE_ID को उस फ़ाइल के fileId से बदलें जिसे आपको जोड़ना है चेक करें.

सैंपल कोड चलाने पर, यह तरीका ContentRestriction संसाधन मौजूद हो.

कॉन्टेंट पर पाबंदी लगाएं, सिर्फ़ फ़ाइल का मालिक बदलाव कर सकता है

फ़ाइल पर पाबंदी लगाने के लिए, ताकि फ़ाइल के मालिक ही उसे लागू करने की सुविधा को टॉगल कर सकें, files.update तरीके का इस्तेमाल इसके साथ करें contentRestrictions.ownerRestricted बूलियन फ़ील्ड को true पर सेट किया गया है. कॉन्टेंट बनाने इस कोड सैंपल में, फ़ाइल के मालिकों के लिए कॉन्टेंट पर पाबंदी लगाने का तरीका बताया गया है सिर्फ़:

Java

File updatedFile =
  new File()
      .setContentRestrictions(
          ImmutableList.of(new ContentRestriction().setReadOnly(true).setOwnerRestricted(true).setReason("Finalized contract."));

File response = driveService.files().update("FILE_ID", updatedFile).setFields("contentRestrictions").execute();

Python

content_restriction = {'readOnly': True, 'ownerRestricted': True, 'reason':'Finalized contract.'}

response = drive_service.files().update(fileId="FILE_ID", body = {'contentRestrictions' : [content_restriction]}, fields = "contentRestrictions").execute();

Node.js

/**
* Set an owner restricted content restriction on a file.
* @return{obj} updated file
**/
async function addOwnerRestrictedContentRestriction() {
  // Get credentials and build service
  // TODO (developer) - Use appropriate auth mechanism for your app

  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});
  const service = google.drive({version: 'v3', auth});
  const contentRestriction = {
    'readOnly': True,
    'ownerRestricted': True,
    'reason': 'Finalized contract.',
  };
  const updatedFile = {
    'contentRestrictions': [contentRestriction],
  };
  try {
    const response = await service.files.update({
      fileId: 'FILE_ID',
      resource: updatedFile,
      fields: 'contentRestrictions',
    });
    return response;
  } catch (err) {
    // TODO (developer) - Handle error
    throw err;
  }
}

FILE_ID को उस फ़ाइल के fileId से बदलें जिसे आपको जोड़ना है बदलें.

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

ownerRestricted फ़्लैग को हटाने के लिए, files.update तरीके का इस्तेमाल contentRestrictions.ownerRestricted फ़ील्ड को false पर सेट किया गया.

कॉन्टेंट पर पाबंदी लगाने की सुविधाएं

files संसाधन में यह शामिल होता है बूलियन capabilities फ़ील्ड का कलेक्शन, जिसका इस्तेमाल यह बताने के लिए किया जाता है कि कोई कार्रवाई है या नहीं किसी फ़ाइल पर काम किया जा सकता है.

कॉन्टेंट पर पाबंदियों में ये capabilities शामिल हैं:

ज़्यादा जानकारी के लिए, यह देखें क्षमताएं.

capabilities फ़ाइल को फिर से पाने के उदाहरण के लिए, उपयोगकर्ता की पुष्टि करें देखें अनुमतियां हैं.

उपयोगकर्ताओं को आपकी फ़ाइल डाउनलोड, प्रिंट या कॉपी करने से रोकें

यह तय किया जा सकता है कि role=commenter या role=reader की अनुमतियों वाले उपयोगकर्ता किस तरह ऐक्सेस कर सकते हैं Drive में मौजूद फ़ाइलें डाउनलोड, प्रिंट, और कॉपी करें. Docs, Sheets, और Slides.

फ़ाइलें डाउनलोड, प्रिंट, और कॉपी करने के विकल्प हटाने के लिए, files.update तरीका copyRequiresWriterPermission बूलियन फ़ील्ड को true पर सेट किया गया.