파일 콘텐츠 보호

Google Drive API는 파일 수정을 방지하기 위해 다음을 비롯한 여러 방법을 지원합니다. 파일 콘텐츠 제한 및 다운로드, 인쇄 또는 복사 옵션 금지 할 수 있습니다.

Drive 콘텐츠 제한을 사용하여 파일을 읽기 전용으로 설정하기

사용자가 다음 작업을 하지 못하도록 Google 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, 슬라이드, 바이너리 파일)
  • 바이너리 파일의 버전
  • Docs의 텍스트 및 서식
  • Sheets의 텍스트 또는 수식, Sheets 레이아웃 Sheets의 인스턴스
  • 프레젠테이션의 모든 콘텐츠뿐 아니라 슬라이드

특정 파일 형식에는 콘텐츠 제한이 포함될 수 없습니다. 몇 가지 예는 다음과 같습니다.

콘텐츠 제한 추가

파일 콘텐츠 제한을 추가하려면 files.update 메서드를 contentRestrictions.readOnly 필드가 true로 설정되었습니다. reason(선택사항) 추가 제한을 추가하는 이유(예: '최종 계약') 다음 코드 샘플은 콘텐츠 제한을 추가하는 방법을 보여줍니다.

자바

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 드라이브 사용자 인터페이스 (UI). 이 파일이 읽기 전용으로 변경되었습니다.

Drive 파일 목록에 콘텐츠 제한이 있는 파일입니다.
그림 1. Drive 파일 목록에 콘텐츠 제한이 있는 파일

콘텐츠 제한 삭제하기

파일 콘텐츠 제한을 삭제하려면 files.update 메서드를 다음과 함께 사용합니다. contentRestrictions.readOnly 필드가 false로 설정되었습니다. 다음 코드 샘플 콘텐츠 제한을 삭제하는 방법을 보여줍니다.

자바

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 UI를 사용하여 콘텐츠 제한을 삭제하고 콘텐츠 수정을 허용합니다 (올바른 권한이 있는 경우). 두 가지 이 작업을 수행하려면 다음 옵션을 사용하세요.

  1. Drive에서 콘텐츠 제한이 있는 파일을 마우스 오른쪽 버튼으로 클릭하고 잠금 해제 를 클릭합니다.

    Drive 파일 목록 내에서 파일 콘텐츠 제한을 삭제합니다.
    그림 2. Drive 파일 목록 내에서 파일 콘텐츠 제한 삭제하기
    를 통해 개인정보처리방침을 정의할 수 있습니다.
  2. 콘텐츠 제한이 있는 파일을 열고 (잠금 모드)를 클릭합니다. > 파일 잠금 해제

    문서 내에서 파일 콘텐츠 제한을 삭제합니다.
    그림 3. 문서 내에서 파일 콘텐츠 제한을 삭제합니다.
    를 통해 개인정보처리방침을 정의할 수 있습니다.

콘텐츠 제한 확인하기

콘텐츠 제한을 확인하려면 files.get 메서드를 contentRestrictions에서 반환된 필드입니다. 다음 코드 샘플은 콘텐츠 제한 상태를 확인합니다.

자바

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 메서드를 사용합니다. true로 설정된 contentRestrictions.ownerRestricted 불리언 필드. 이 다음 코드 샘플은 파일 소유자에 대한 콘텐츠 제한을 추가하는 방법을 보여줍니다. 다음만:

자바

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 사용자 인터페이스 (UI). 만약 소유자가 아닌 경우 자물쇠 기호가 흐리게 표시됩니다.

ownerRestricted 플래그를 삭제하려면 files.update 메서드를 다음과 함께 사용합니다. contentRestrictions.ownerRestricted 필드가 false(으)로 설정됨

콘텐츠 제한 기능

files 리소스에는 작업인지 여부를 나타내는 데 사용되는 불리언 capabilities 필드 컬렉션 작업을 수행할 수 있습니다.

콘텐츠 제한에는 다음 capabilities가 포함됩니다.

  • capabilities.canModifyEditorContentRestriction: 현재 사용자가 콘텐츠 제한을 추가하거나 수정할 수 있습니다.
  • capabilities.canModifyOwnerContentRestriction: 현재 사용자가 소유자 콘텐츠 제한을 추가하거나 수정할 수 있습니다.
  • capabilities.canRemoveContentRestriction: 현재 사용자가 적용된 콘텐츠 제한 (있는 경우)을 삭제합니다.

자세한 내용은 기능.

capabilities 파일을 가져오는 예는 사용자 확인 권한이 있는지 확인합니다.

사용자가 파일을 다운로드, 인쇄, 복사하지 못하도록 차단

role=commenter 또는 role=reader 권한이 있는 사용자가 수행할 수 있는 방법을 제한할 수 있습니다. Drive 내 파일 다운로드, 인쇄, 복사하기 Docs, Sheets, Slides

파일 다운로드, 인쇄, 복사 옵션을 삭제하려면 files.update 메서드를 copyRequiresWriterPermission 불리언 필드가 true로 설정되었습니다.