Google Drive API는 파일 콘텐츠 제한, 파일 다운로드, 인쇄, 복사 옵션 금지 등 파일 수정을 방지하는 여러 방법을 지원합니다.
Drive 콘텐츠 제한을 사용해 파일을 읽기 전용으로 설정하기
Google Drive 파일에 콘텐츠 제한을 추가하여 사용자가 다음을 하지 못하도록 할 수 있습니다.
- 제목 수정하기
- 콘텐츠 수정하기
- 버전 업로드
- 댓글 추가 또는 수정
콘텐츠 제한을 적용하는 것은 항목의 액세스 권한을 변경하지 않고 Drive 항목의 콘텐츠를 읽기 전용으로 만드는 메커니즘입니다. 즉, 액세스 제한이 아닙니다. 사용자는 파일의 콘텐츠를 수정할 수 없지만 액세스 수준에 따라 다른 작업은 계속 허용됩니다. 예를 들어 수정 액세스 권한이 있는 사용자는 계속해서 항목을 이동하거나 공유 설정을 변경할 수 있습니다.
Drive의 파일에 관한 콘텐츠 제한을 추가하거나 삭제하려면 사용자에게 관련 권한이 있어야 합니다. 내 드라이브의 파일 또는 폴더 또는 capabilities.canModifyEditorContentRestriction
가 있는 공유 드라이브의 경우 role=writer
을 할당해야 합니다. 내 드라이브의 파일 또는 폴더 또는 ownerRestricted
콘텐츠 제한이 있는 공유 드라이브의 경우 파일을 소유하거나 role=organizer
이 있어야 합니다. 콘텐츠 제한이 있는 항목을 보려면 사용자에게 role=reader
이상이 필요합니다. 전체 역할 목록은 역할 및 권한을 참조하세요. 파일에 대한 권한을 변경하려면 권한 변경을 참조하세요.
files
리소스의 contentRestrictions.readOnly
불리언 필드를 사용하여 콘텐츠 제한을 설정할 수 있습니다. 항목에 콘텐츠 제한을 설정하면 기존 항목을 덮어씁니다.
콘텐츠 제한 시나리오
Drive 항목의 콘텐츠 제한은 사용자에게 콘텐츠를 변경하면 안 된다는 신호를 보냅니다. 여기에는 다음과 같은 이유가 있을 수 있습니다.
- 검토 또는 감사 기간에 공동작업 문서의 작업을 일시중지합니다.
- 항목을 승인됨과 같은 확정된 상태로 설정하는 경우
- 민감한 회의 중에 변경 방지
- 자동화 시스템에서 처리하는 워크플로의 외부 변경 금지
- Google Apps Script 및 Google Workspace 부가기능으로 수정 제한
- 문서를 실수로 수정하는 것을 방지합니다.
콘텐츠 제한은 콘텐츠 관리에 도움이 될 수 있지만 충분한 권한을 가진 사용자가 항목에서 계속 작업하지 못하게 하는 것은 아닙니다. 또한 변경할 수 없는 레코드를 만드는 방법도 아닙니다. Drive 콘텐츠 제한은 변경될 수 있으므로 항목의 콘텐츠 제한이 있더라도 항목이 변경되지 않는다는 보장은 없습니다.
콘텐츠 제한이 있는 파일 관리하기
Google Docs, Google Sheets, Google Slides와 다른 모든 파일에는 콘텐츠 제한이 포함될 수 있습니다.
항목에 관한 콘텐츠 제한을 적용하면 다음을 비롯하여 제목과 콘텐츠를 변경할 수 없습니다.
- 댓글 및 제안 (Docs, Sheets, Slides, 바이너리 파일)
- 바이너리 파일의 버전
- Docs의 텍스트 및 서식
- Sheets의 텍스트 또는 수식, Sheets 레이아웃, Sheets의 인스턴스
- Slides의 모든 콘텐츠, 슬라이드의 순서 및 개수
특정 파일 형식에는 콘텐츠 제한을 포함할 수 없습니다. 몇 가지 예는 다음과 같습니다.
- Google Forms
- Google 사이트 도구
- Google Drawings
- 바로가기 및 서드 파티 바로가기 자세한 내용은 앱에서 저장하는 콘텐츠의 바로가기 파일 만들기 및 드라이브 파일 바로가기 만들기를 참고하세요.
콘텐츠 제한 추가
파일 콘텐츠 제한을 추가하려면 contentRestrictions.readOnly
필드가 true
로 설정된 files.update
메서드를 사용합니다. 제한사항을 추가하는 이유에 관한 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 사용자 인터페이스(UI) 내의 파일 이름 옆에 자물쇠 기호( )가 표시됩니다. 이제 파일은 읽기 전용입니다.
콘텐츠 제한 삭제
파일 콘텐츠 제한을 삭제하려면 contentRestrictions.readOnly
필드가 false
로 설정된 files.update
메서드를 사용합니다. 다음 코드 샘플은 콘텐츠 제한을 삭제하는 방법을 보여줍니다.
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 UI를 사용하여 콘텐츠 제한을 삭제하고 콘텐츠 수정을 허용할 수도 있습니다 (올바른 권한이 있는 경우). 여기에는 두 가지 옵션이 있습니다.
Drive에서 콘텐츠 제한이 있는 파일을 마우스 오른쪽 버튼으로 클릭하고 잠금 해제
를 클릭합니다.콘텐츠 제한이 있는 파일을 열고 (잠금 모드) > 파일 잠금 해제를 클릭합니다.
콘텐츠 제한 확인
콘텐츠 제한을 확인하려면 contentRestrictions
반환 필드와 함께 files.get
메서드를 사용합니다. 다음 코드 샘플은 콘텐츠 제한 상태를 확인하는 방법을 보여줍니다.
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
리소스가 있으면 이를 반환합니다.
파일 소유자만 수정할 수 있는 콘텐츠 제한을 추가합니다.
파일 소유자만 메커니즘을 전환할 수 있도록 파일 콘텐츠 제한을 추가하려면 contentRestrictions.ownerRestricted
불리언 필드가 true
로 설정된 files.update
메서드를 사용합니다. 다음 코드 샘플은 파일 소유자 전용 콘텐츠 제한을 추가하는 방법을 보여줍니다.
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 사용자 인터페이스 (UI) 내의 파일 이름 옆에 활성 자물쇠 기호( )가 표시됩니다. 소유자가 아닌 경우 자물쇠 기호가 흐리게 표시됩니다.
ownerRestricted
플래그를 삭제하려면 contentRestrictions.ownerRestricted
필드가 false
로 설정된 files.update
메서드를 사용합니다.
콘텐츠 제한 기능
files
리소스에는 파일에서 작업을 실행할 수 있는지 여부를 나타내는 데 사용되는 불리언 capabilities
필드 모음이 포함됩니다.
콘텐츠 제한에는 다음과 같은 capabilities
가 포함됩니다.
capabilities.canModifyEditorContentRestriction
: 현재 사용자가 콘텐츠 제한을 추가하거나 수정할 수 있는지 여부입니다.capabilities.canModifyOwnerContentRestriction
: 현재 사용자가 소유자 콘텐츠 제한을 추가하거나 수정할 수 있는지 여부입니다.capabilities.canRemoveContentRestriction
: 현재 사용자가 적용된 콘텐츠 제한 (있는 경우)을 삭제할 수 있는지 여부입니다.
자세한 내용은 기능을 참조하세요.
capabilities
파일을 검색하는 예시는 사용자 권한 확인을 참조하세요.
사용자가 파일을 다운로드, 인쇄, 복사하지 못하도록 차단하기
role=commenter
또는 role=reader
권한이 있는 사용자가 Drive, Docs, Sheets, Slides에서 파일을 다운로드, 인쇄, 복사하는 방법을 제한할 수 있습니다.
파일 다운로드, 인쇄, 복사 옵션을 삭제하려면 copyRequiresWriterPermission
불리언 필드가 true
로 설정된 files.update
메서드를 사용합니다.