ファイルをコピー

post
https://api.box.com/2.0
/files/:file_id/copy

ファイルのコピーを作成します。

リクエスト

application/json

パスパラメータ

stringパス内必須
12345

ファイルを表す一意の識別子。

ファイルIDを確認するには、ウェブアプリケーションでファイルにアクセスして、URLからIDをコピーします。たとえば、URLがhttps://*.app.box.com/files/123の場合、file_id123です。

クエリパラメータ

string arrayクエリ内省略可能
id,type,name

応答に含める属性のカンマ区切りリスト。このパラメータを使用すると、標準の応答には通常含まれないフィールドをリクエストできます。

このパラメータを指定すると、明示的に指定しない限り標準フィールドは応答に含まれず、リクエストしたフィールドのほかには、簡易版レプリゼンテーションのフィールドしか返されないことに注意してください。

リクエスト本文

string本文内省略可能
FileCopy.txt255

コピーされたファイルの新しい名前(省略可)。

ファイル名にはいくつかの制約があります。印刷不可能なASCII文字、スラッシュ、およびバックスラッシュ(/\)を含む名前のほか、...のような予約済みの名前は、許可されていない文字を削除することで自動的にサニタイズされます。

object本文内

ファイルのコピー先となるフォルダ。

stringnull省略可能
0

ファイルのコピー先となるフォルダのID。

string本文内省略可能
0

コピーする特定のファイルバージョンのID(省略可)

レスポンス

application/jsonFile

コピーされたファイルを表す新しいファイルオブジェクトを返します。

使用可能なすべてのフィールドがデフォルトで返されるとは限りません。特定のフィールドを明示的にリクエストするには、fieldsクエリパラメータを使用します。

none

If-None-Matchヘッダーがファイルの現在のetag値と一致する場合は、空の応答を返します。これは、ファイルが前回リクエストされたときから変更されていないことを示します。

一部のパラメータが指定されていないか無効な場合はエラーを返します。

  • bad_request - パラメータが指定されていない場合に返されます。

ソースファイルまたは宛先フォルダのどちらも見つからないか、認証済みユーザーがどちらにもアクセスできない場合はエラーを返します。

  • not_found - 認証済みユーザーがソースファイルまたは宛先フォルダにアクセスできない場合に返されます
  • operation_blocked_temporary: 別の移動、コピー、削除、または復元操作が進行中であるために宛先フォルダまたは元のフォルダがロックされている場合に返されます。

    操作は後で再試行することができます。

  • item_name_in_use: 同じ名前のフォルダがすでに存在する場合に返されます。

予期しないクライアントエラー。

post
ファイルをコピー
このドキュメント内で一部のAPIを試せるようになりました。
ログイン

リクエストの例

cURL
curl -X POST https://api.box.com/2.0/files/12345/copy \
     -H 'Authorization: Bearer <ACCESS_TOKEN>" '
     -H 'Content-Type: application/json" '
     -d '{
       "parent": {
         "id": "123"
       }
     }'
.NET
string fileId = "11111";
string destinationFolderId = "22222";
var requestParams = new BoxFileRequest()
{
    Id = fileId,
    Parent = new BoxRequestEntity()
    {
        Id = destinationFolderId
    }
};

BoxFile fileCopy = await client.FilesManager.CopyAsync(requestParams);
Java
// Copy a file into the user's root folder
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
BoxFile file = new BoxFile(api, "id");
BoxFile.Info copiedFileInfo = file.copy(rootFolder, "New Name");
Python
file_id = '11111'
destination_folder_id = '44444'

file_to_copy = client.file(file_id)
destination_folder = client.folder(destination_folder_id)

file_copy = file_to_copy.copy(destination_folder)
print('File "{0}" has been copied into folder "{1}"'.format(file_copy.name, file_copy.parent.name))
Node
var fileID = '11111';
var destinationFolderID = '22222';
client.files.copy(fileID, destinationFolderID)
	.then(fileCopy => {
		/* fileCopy -> {
			type: 'file',
			id: '11112',
			file_version: 
				{ type: 'file_version',
				id: '99999',
				sha1: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' },
			sequence_id: '0',
			etag: '0',
			sha1: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33',
			name: 'My File.pdf',
			description: '',
			size: 68431,
			path_collection: 
				{ total_count: 1,
				entries: 
				[ { type: 'folder',
					id: '0',
					sequence_id: null,
					etag: null,
					name: 'All Files' },
					{ type: 'folder',
					id: '22222',
					sequence_id: null,
					etag: null,
					name: 'Personal Files' } ] },
			created_at: '2017-05-16T15:18:02-07:00',
			modified_at: '2017-05-16T15:18:02-07:00',
			trashed_at: null,
			purged_at: null,
			content_created_at: '2017-05-16T15:18:02-07:00',
			content_modified_at: '2017-05-16T15:18:02-07:00',
			created_by: 
				{ type: 'user',
				id: '33333',
				name: 'Test User',
				login: 'test@example.com' },
			modified_by: 
				{ type: 'user',
				id: '33333',
				name: 'Test User',
				login: 'test@example.com' },
			owned_by: 
				{ type: 'user',
				id: '33333',
				name: 'Test User',
				login: 'test@example.com' },
			shared_link: null,
			parent: 
				{ type: 'folder',
				id: '22222',
				sequence_id: null,
				etag: null,
				name: 'Personal Files' }
			item_status: 'active' }
		*/
	});
iOS
client.files.copy(fileId: "11111", parentId: "0") { (result: Result<File, BoxSDKError>) in
    guard case let .success(copiedFile) = result else {
        print("Error copying file")
        return
    }

    print("Copied file \(copiedFile.name) into folder \(copiedFile.parent.name); copy has file ID \(copiedFile.id)")
}