Save metadata

To associate metadata with a media item you first need to create/lookup the MetadataDefinition for the metadata value you need to store.


A Metadata definition describes a Metadata. It contains the name of the metadata, type (integer, string etc), definition type (User, IPTC, EXIF etc.) and other properties. To be able to enter a metadata for a media item you need to have the corresponding id of the definition.


To retrieve the existing metadata definitions from ImageVault, see example below.

var client = ClientFactory.GetSdkClient();
var metadataDefinitions =
    client.Query<MetadataDefinition>().Where(d => d.MetadataDefinitionType == MetadataDefinitionTypes.User).ToList();
foreach (var metadataDefinition in metadataDefinitions) {
    Console.WriteLine(metadataDefinition.Name + ", " + metadataDefinition.Id + "," + metadataDefinition.MetadataType);


Many MetadataDefinitions are created when uploading media to ImageVault since the media analyzers finds existing metadata in the file but you can create your own metadata if need be. It's recommended to use the MetdataDefinitionType.User to define your own metadata.

To create a metadata definition, follow the example below.

var client = ClientFactory.GetSdkClient();
var metadataDefinitionService = client.CreateChannel<IMetadataDefinitionService>();
var metadataDefinition = new MetadataDefinition {
    Name = "Serial number",
    Description = "The serial number for this item",
    MetadataType = MetadataTypes.String,
    MetadataDefinitionType = MetadataDefinitionTypes.User
//the id gets returned from the save method, store it in the object
metadataDefinition.Id = metadataDefinitionService.Save(metadataDefinition);

Adding metadata to a media item

To add metadata to a media item you add the Metadata instances to the Metadata list of the MediaItem. Only specify the MetadataDefinitionId and the value of the metadata that you want to store.

//create the metadata value and specify value and MetadataDefinitionId
var descriptionMetadata = new MetadataLongString
    MetadataDefinitionId = descriptionMetadataDefinition.Id,
    LongStringValue = "Description of this item @" + DateTime.Now.ToShortTimeString(),

//we only want to save the specific metadata (all other are untouched)
//to remove a metadata, set its value to null.

var mediaService = client.CreateChannel<IMediaService>();

//save the mediaItem but only the metadata
mediaService.Save(new List<MediaItem> {mediaItem}, MediaServiceSaveOptions.Metadata);

Note: Existing metadata values will not be affected, only supplied metadata will be added/modified/deleted. Note2: To delete an existing metadata for a mediaItem you need to save its value as null.

comments powered by Disqus
+46 (0)480 - 31 47 95
Swedish website