Copy a File

Copies a file.

Note: For more information about this command, including descriptions of any path and request parameters, request body schema, response codes and schemas, and payload examples, refer to the online API reference for this command at the following web page:

Copy a file

URI

https://bartendercloud.com/api/librarian/files/{fileId}/copy

Note: The bartendercloud.com domain that is referenced in the URI and in the code example that follows must be replaced with the contents of the DataCenterURI claim that is extracted from your access token. For more information, refer to Extracting the DataCenterURI Claim.

Path Parameters

fileId

Type: String

Specifies the ID of the file to copy. Required.

Query Parameters

versionMajor

Type: Integer <int32>

Specifies the requested major version. Gets the latest version if both major and minor versions are not provided. Also gets the latest version if a major version is not provided and if minor versioning is not enabled in the space, regardless of the minor version value. Optional.

versionMinor

Type: Integer <int32>

Specifies the requested minor version. Required when minor versioning is enabled in the space; otherwise optional.

Example

Request body: See FileCopyRequest.

Response: A FileChange object is returned that provides details about the file.

Copy
// Assume that fileId is the ID of the target file. 
// Assume that destinationFolderId is the ID of the folder that will receive the new copied file.
var copyRequest = new FileCopyRequest() {
   FileName = "Copied SQL File",
   DestinationFolderId = detinationFolderId,
   DestinationComment = "Copied from SQL File version 1.1"
};

var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");

HttpRequestMessage request = new HttpRequestMessage
{
   RequestUri = new Uri($"https://bartendercloud.com/api/librarian/files/{fileId}/copy?versionMajor=1&versionMinor=1"),
   Content = new StringContent(JsonConvert.SerializeObject(copyRequest), Encoding.UTF8, "application/json"),
   Method = HttpMethod.Post
};

HttpResponseMessage msg = await client.SendAsync(request);

if (msg.IsSuccessStatusCode)
{
   return JsonConvert.DeserializeObject<FileChange>(await msg.Content.ReadAsStringAsync());
}