Creates a copy of a file.
12345
The unique identifier that represent a file.
The ID for any file can be determined
by visiting a file in the web application
and copying the ID from the URL. For example,
for the URL https://*.app.box.com/files/123
the file_id
is 123
.
id,type,name
A comma-separated list of attributes to include in the response. This can be used to request fields that are not normally returned in a standard response.
Be aware that specifying this parameter will have the effect that none of the standard fields are returned in the response unless explicitly specified, instead only fields for the mini representation are returned, additional to the fields requested.
FileCopy.txt
255
An optional new name for the copied file.
There are some restrictions to the file name. Names containing
non-printable ASCII characters, forward and backward slashes
(/
, \
), and protected names like .
and ..
are
automatically sanitized by removing the non-allowed
characters.
The destination folder to copy the file to.
0
The ID of folder to copy the file to.
0
An optional ID of the specific file version to copy.
Returns an empty response when the If-None-Match
header matches
the current etag
value of the file. This indicates that the file
has not changed since it was last requested.
Returns an error if some of the parameters are missing or not valid.
bad_request
when a parameter is missing.Returns an error if either the source file or the destination folder could not be found, or the authenticated user does not have access to either.
not_found
when the authenticated user does not have access
to the source file or the destination folderoperation_blocked_temporary
: Returned if either of the destination
or source folders is locked due to another move, copy, delete or
restore operation in process.
The operation can be retried at a later point.
item_name_in_use
when a folder with the same name already
exists.An unexpected client error.
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"
}
}'
string fileId = "11111";
string destinationFolderId = "22222";
var requestParams = new BoxFileRequest()
{
Id = fileId,
Parent = new BoxRequestEntity()
{
Id = destinationFolderId
}
};
BoxFile fileCopy = await client.FilesManager.CopyAsync(requestParams);
// 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");
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))
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' }
*/
});
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)")
}