Question

I am trying to retrieve the Binary Url of a multimedia component's file that is published as a dynamic Component Presentation.

I can see the Url in the Binaries table within the Broker database but I can't seem to get the binary url using either of the following bits of code:

using SQLBinaryMetaHome:

using (var sqlBinMetaHome = new Com.Tridion.Broker.Binaries.Meta.SQLBinaryMetaHome())
{
    int componentItemId = int.Parse(queryStringId.Split('-')[1]);
    var binaryMeta = sqlBinMetaHome.FindByPrimaryKey(new TCDURI(publicationId, 16, componentItemId));

    if (binaryMeta != null)
    {
        VideoBinaryUrl = binaryMeta.GetURLPath();
    }
    else
    {
        Logger.Log.ErrorFormat("Failed ot load via SQL Binary Meta {0}", queryStringId);
    }
}                        

Using Binary Meta factory:

using (var b = new BinaryMetaFactory())
{
    var binaryMeta = b.GetMeta(queryStringId);
    if (binaryMeta != null)
    {
        VideoBinaryUrl = binaryMeta.UrlPath;
    }
    else
    {
        Logger.Log.ErrorFormat("Failed to load binary meta {0}", queryStringId);
    }
}

I can load the Component Meta data using the ComponentMetaFactory.

Any ideas on why I can't load the Binary Meta? Am I on the right track?

Rob

Was it helpful?

Solution

Is there a reason you are not using a Binary Link to get a Link object to the specific Variant of the binary you want? Keep in mind that any DCP may render multiple variations of your multimedia component. From the Link object you can then get the URL to the binary.

Look for BinaryLink in the documentation for more details.

OTHER TIPS

It looks like your first example is importing (auto-generated) methods from an internal DLL (Tridion.ContentDelivery.Interop.dll). Please don't use those and stick to the ones in the Tridion.ContentDelivery namespace (Tridion.ContentDelivery.dll).

You can find the official documentation for the Content Delivery .NET API in CHM format on SDL Tridion World (click the link, log in to the site and click the link again). From that documentation comes this example:

//create a new BinaryMetaFactory instance:
BinaryMetaFactory binaryMetaFactory = new BinaryMetaFactory();
//find the metadata for the specified binary
BinaryMeta binaryMeta = binaryMetaFactory.GetBinaryMeta("tcm:1-123");
//print the path to the output stream:
if(binaryMeta!=null) {
    Response.Write("Path of the binary: " + binaryMeta.UrlPath);
}
//Dispose the BinaryMetaFactory
binaryMetaFactory.Dispose();

The factory class is Tridion.ContentDelivery.Meta.BinaryMetaFactory from Tridion.ContentDelivery.dll. I indeed also can't find a GetBinaryMeta method in that class, so it seems there is a mistake in the code sample. The most likely method that you should use is GetMeta.

Try this:-

 BinaryMeta binaryMeta = b.GetBinaryMeta(queryStringId);
 if(binaryMeta != null) {
       VideoBinaryUrl = binaryMeta.URLPath;
 }

I did a SQL Profiler on the code and noticed that it was because I deployed my test app it wasn't calling the broker. Running the code within the actual Tridion Published site did hit the database but it was passing the value "[#def#]" for the variantId column.

I have now got it working with the following code:

IComponentMeta cm = cmf.GetMeta(queryStringId);
if (cm != null)
{
    TcmId = queryStringId;
    Title = cm.TryGetValue("title");
    Summary = cm.TryGetValue("summary");
    Product = cm.TryGetValue("product");


    if (cm.SchemaId == StreamingContentSchemaId)
    {
        VideoId = cm.TryGetValue("video_url");
        IsVimeo = true;
    }
    else if (cm.SchemaId == WebcastSchemaId)
    {
        using (var b = new BinaryMetaFactory())
        {
            var binaryMeta = b.GetMeta(queryStringId, "tcm:0-" + cm.OwningPublicationId + "-1");
            if (binaryMeta != null)
            {
                VideoBinaryUrl = binaryMeta.UrlPath;
            }
            else
            {
                Logger.Log.ErrorFormat("Failed to load binary meta {0}", queryStringId);
            }
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top