ファイルとフォルダの転送
ファイルとフォルダの転送
ユーザーアカウントのプロビジョニング解除における一般的な要件の1つが、ユーザーアカウント内に保存されているすべてのファイルとフォルダを別のユーザーアカウント、またはサービスアカウントなどの長期保存用の場所に転送することです。
Box内でこれを実行するのに使用される一般的な方法は以下の2つです。
- すべてのコンテンツをあるユーザーから別のユーザーに直接移動する、所有フォルダを移行APIを使用する。
- コラボレーション転送の方法を使用して、一度に1つのファイルまたはフォルダの所有権を、あるユーザーから別のユーザーに変更する。
所有フォルダを移行APIの使用
所有フォルダを移行エンドポイントは、あるユーザーが所有するコンテンツ全体を別のユーザーに移動することを目的に設計されています。
転送エンドポイントを呼び出すには、転送元のユーザーIDと転送先のユーザーIDを指定します。
curl -X PUT https://api.box.com/2.0/users/12345/folders/0 \
-H 'Authorization: Bearer <ACCESS_TOKEN>" '
-H 'Content-Type: application/json" '
-d '{
"owned_by": {
"id": "1232234"
}
}'
var sourceUserId = "33333";
var destinationUserId = "44444";
BoxFolder movedFolder = await client.MoveUserFolderAsync(sourceUserId, destinationUserId);
String sourceUserID = "11111";
String destinationUserID = "22222";
BoxUser sourceUser = new BoxUser(api, sourceUserID);
BoxFolder.Info transferredFolderInfo = sourceUser.transferContent(destinationUserID);
source_user_id = '33333'
destination_user_id = '44444'
user = client.user(source_user_id)
destination_user = client.user(destination_user_id)
folder = user.transfer_content(destination_user)
print('Created new folder "{0}" in the account of user {1}'.format(folder.name, destination_user.id))
var sourceUserID = '33333';
var destinationUserID = '44444';
client.enterprise.transferUserContent(sourceUserID, destinationUserID)
.then(movedFolder => {
/* movedFolder -> {
type: 'folder',
id: '123456789',
sequence_id: '1',
etag: '1',
name: 'Other User's Files and Folders',
created_at: '2018-04-23T11:00:07-07:00',
modified_at: '2018-04-23T11:00:07-07:00',
description: 'This folder contains files previously owned by Other User, and were transferred to you by your enterprise administrator. If you have any questions, please contact Enterprise Admin (admin@example.com).',
size: 0,
path_collection:
{ total_count: 1,
entries:
[ { type: 'folder',
id: '0',
sequence_id: null,
etag: null,
name: 'All Files' } ] },
created_by:
{ type: 'user',
id: '99999',
name: 'Enterprise Admin',
login: 'admin@example.com' },
modified_by:
{ type: 'user',
id: '99999',
name: 'Enterprise Admin',
login: 'admin@example.com' },
trashed_at: null,
purged_at: null,
content_created_at: '2018-04-23T11:00:07-07:00',
content_modified_at: '2018-04-23T11:00:07-07:00',
owned_by:
{ type: 'user',
id: '33333',
name: 'Example User',
login: 'user@example.com' },
shared_link: null,
folder_upload_email: null,
parent:
{ type: 'folder',
id: '0',
sequence_id: null,
etag: null,
name: 'All Files' },
item_status: 'active' }
*/
});
client.users.moveItemsOwnedByUser(withID: "33333", toUserWithID: "44444") { (result: Result<Folder, BoxSDKError>) in
guard case let .success(folder) = result else {
print("Error moving user content")
return
}
print("Folder ID \(folder.id) created with migrated content")
}
コラボレーション転送の使用
コラボレーション転送は、コラボレーションエンドポイントを使用して、単一のファイルまたはフォルダの所有権をあるユーザーから別のユーザーに即座に変更するプロセスです。
transfer_from_user
からtransfer_to_user
への転送の一般的なプロセスは以下の手順に従います。
転送先ユーザーを共同所有者として追加
最初の手順は、転送するファイルまたはフォルダへのco-owner
アクセス権限を持つコラボレータとして、transfer_to_user
アカウントを追加することです。
transfer_from_user
アカウントとして呼び出しを行い、コラボレーションを追加エンドポイントを使用してtransfer_to_user
を共同所有者として追加します。
curl -X POST https://api.box.com/2.0/collaborations \
-H 'Authorization: Bearer <ACCESS_TOKEN>" '
-H 'Content-Type: application/json" '
-d '{
"item": {
"type": "file",
"id": "11446498"
},
"accessible_by": {
"type": "user",
"login": "123456"
},
"role": "editor"
}'
// collaborate folder 11111 with user 22222
BoxCollaborationRequest requestParams = new BoxCollaborationRequest()
{
Item = new BoxRequestEntity()
{
Type = BoxType.Folder,
Id = "11111"
},
Role = "editor",
AccessibleBy = new BoxCollaborationUserRequest()
{
Id = "22222"
}
};
BoxCollaboration collab = await client.CollaborationsManager.AddCollaborationAsync(requestParams);
BoxCollaborator user = new BoxUser(api, "user-id")
BoxFolder folder = new BoxFolder(api, "folder-id");
folder.collaborate(user, BoxCollaboration.Role.EDITOR);
from boxsdk.object.collaboration import CollaborationRole
user = client.user(user_id='11111')
collaboration = client.folder(folder_id='22222').collaborate(user, CollaborationRole.VIEWER)
collaborator = collaboration.accessible_by
item = collaboration.item
has_accepted = 'has' if collaboration.status == 'accepted' else 'has not'
print('{0} {1} accepted the collaboration to folder "{2}"'.format(collaborator.name, has_accepted, item.name))
// Invite user 123456 to collaborate on folder 987654
client.collaborations.createWithUserID('123456', '987654', client.collaborationRoles.EDITOR)
.then(collaboration => {
/* collaboration -> {
type: 'collaboration',
id: '11111',
created_by:
{ type: 'user',
id: '22222',
name: 'Inviting User',
login: 'inviter@example.com' },
created_at: '2016-11-16T21:33:31-08:00',
modified_at: '2016-11-16T21:33:31-08:00',
expires_at: null,
status: 'accepted',
accessible_by:
{ type: 'user',
id: '123456',
name: 'Collaborator User',
login: 'collaborator@example.com' },
role: 'editor',
acknowledged_at: '2016-11-16T21:33:31-08:00',
item:
{ type: 'folder',
id: '987654',
sequence_id: '0',
etag: '0',
name: 'Collaborated Folder' } }
*/
});
client.collaborations.create(
itemType: "folder",
itemId: "22222",
role: .editor,
accessibleBy: "33333",
accessibleByType: "user"
) { (result: Result<Collaboration, BoxSDKError>) in
guard case let .success(collaboration) = result else {
print("Error creating collaboration")
return
}
print("Collaboration successfully created")
}
転送先ユーザーとしてコラボレーションIDを取得
次のステップでは、コラボレーション情報を取得するリクエストをtransfer_to_user
アカウントとして実行します。返されるコラボレーションオブジェクトには、最後のステップで使用するコラボレーションIDが含まれます。
transfer_to_user
アカウントとして呼び出しを実行し、コラボレーションを取得エンドポイントを使用して、転送するファイルまたはフォルダのIDのコラボレーションを取得します。コラボレーションIDをキャプチャします。
転送元ユーザーを所有者として削除
最後の手順は、ファイルまたはフォルダの所有者としてtransfer_from_user
アカウントを削除することです。これは、コラボレーションを削除エンドポイントを使用して行います。
transfer_to_user
アカウントとして呼び出しを実行し、ファイルまたはフォルダのコラボレータとしてtransfer_from_user
を削除します。
これにより、ファイルまたはフォルダの所有者はtransfer_to_user
アカウントになり、transfer_from_user
アカウントはアクセスできなくなります。