Update a File

Updates a file.

When a user checks a file in to Librarian, a new updated version of that file is created. Whether the updated version is major or minor is specified when the user submits the checkin request and depends on the value of the versionUpdateMethod parameter. For example, if VersionUpdateMethod.Major is specified, then a checkin request against a 1.0 version produces a 2.0 version; if VersionUpdateMethod.Minor is specified, then a checkin request against a 1.0 version produces a 1.1 version.

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:

Update a file

URI

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

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 that is being checked in. Required.

Query Parameters

versionUpdateMethod

Type: Integer <int32> (VersionUpdateMethod)

Specifies whether the major or minor version number should be incremented. Specify either versionUpdateMethod.Major (value = 1) or versionUpdateMethod.Minor (value = 2).

Example

Request body: System.Net.Http.MultipartFormDataContent

Response: See FileChange.

See also: FileUpdateCheckInRequest, VersionUpdateMethod

Copy
// Assume that the stream is of the System.IO.Stream type and references the file content to upload.
// Assume that fileId is the ID of the target file. 
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");

var updateMethod = VersionUpdateMethod.Major;
var fileUpdateCheckInRequest = new FileUpdateCheckInRequest() {
    Comment = "Updating version 1 of this document",
    VersionDescription = "Based on Version 1.0"
};
StreamContent streamContent = new StreamContent(stream);
MultipartFormDataContent multipartFormDataContent = new MultipartFormDataContent
{
   { new StringContent(JsonConvert.SerializeObject(fileUpdateCheckInRequest)), "fileUpdate" },
   { streamContent, "formFile", fileName }
};

var msg = await client.PutAsync($"https://bartendercloud.com/api/librarian/files/{fileId}?versionUpdateMethod={updateMethod}", multipartFormDataContent);

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