1

I have created a Structure group Metadata having image field. when I try to read the image url, I am getting the TCM ID.

ItemFields metadataFields = new ItemFields(objSG.Metadata, objSG.MetadataSchema);
foreach (ItemField metadataField in metadataFields)
{
   if (metadataField.Name == SchemaConstant.StructureGroupMetadataSchema.Image)
   {    
     elmSG.SetAttribute(Image, metadataField.ToString());
   }
}

Result: I am getting the value:

  • image="Component tcm:720-107060"
1
  • Images don't have URLs on the CM side. Your template determines the URL when it publishes the image
    – Nuno Linhares
    Aug 31, 2016 at 8:34

1 Answer 1

2

Images do not have a URL until they are published, as mentioned by @Nuno.

In your code you'll need to publish the binaries to get a URL you can use either the AddBinary or the PublishBinary method to publish binaries. I'd recommend AddBinary, as shown below:

ItemFields metadataFields = new ItemFields(objSG.Metadata, objSG.MetadataSchema);
foreach (ItemField metadataField in metadataFields)
{
   if (metadataField.Name == SchemaConstant.StructureGroupMetadataSchema.Image)
   {    
     //Add Image to package to be published
     var publishedImage = engine.AddBinary(metadataField.value);
     elmSG.SetAttribute(Image, publishedImage.Url);
   }
}

Additional options and parameters for the AddBinary function can be found in the documentation here: https://sdl.dist.sdlmedia.com/Distributions/?o=3E760DAB-B7EF-45DD-9D23-6BDA0B37538C

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.