Add a Metadata Item |
Adds a metadata item by adding a new key-value pair to the metadata that is associated with a file.
Metadata is a collection of name-to-object mappings. Data can be bound to the name for later retrieval. The name (or "key") must be unique and is case-sensitive. The developer is responsible for setting the object value that is associated with this key. The recommended data format is JSON.
The storage that is consumed by a file's metadata must be less than 10MB. If you try to store more than a total of 10MB, a storage error may occur. If you need to associate large data elements with a specific file version, consider using the Add a File Attachment API instead.
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: |
URI
https://bartendercloud.com/api/librarian/files/{fileId}/metadata/{key}
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. Required.
key
Type: String
Specifies the key of the associated metadata item. This parameter must be single-URL encoded. 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
- C#
Request body: See MetadataCreateItemRequest.
Response: System.Collections.Generic.Dictionary<string, object>
// Assume that fileId is the ID of the target file.
// Create the metadata creation request.
var createRequest = new MetadataCreateItemRequest() {
Value = "My metadata value"
};
string keyName = "MyMetadataKey";
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");
HttpRequestMessage request = new HttpRequestMessage() {
RequestUri = new Uri($"https://bartendercloud.com/api/librarian/files/{fileId}/metadata/{key}?versionMajor=1"),
Content = new StringContent(JsonConvert.SerializeObject(createRequest), Encoding.UTF8, "application/json"),
Method = HttpMethod.Post
};
HttpResponseMessage msg = await client.SendAsync(request);
if (msg.IsSuccessStatusCode)
{
// The returned collection of all metadata.
return JsonConvert.DeserializeObject<System.Collections.Generic.Dictionary<string, object>>(await msg.Content.ReadAsStringAsync());
}