1

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

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
Rob Stevenson-Leggett
  • 33,849
  • 21
  • 84
  • 138
  • Does the Multimedia Component show with a "Published" icon in the Tridion Web UI? – Frank van Puffelen May 28 '12 at 18:52
  • What does the second code fragment end up doing? Does it log your error? Or is VideoBinaryUrl simply null/empty? – Frank van Puffelen May 28 '12 at 19:08
  • Hi Frank, both log the error. – Rob Stevenson-Leggett May 28 '12 at 19:56
  • Good. Then at least there is no punishment for sticking to the public API. ;-) So does the MMC show with a published/globe icon in the web GUI? – Frank van Puffelen May 28 '12 at 19:59
  • Yes it does and I can see the metadata by querying the DB directly. I had a similar issue earlier last week and ended up having to use the obsolete filtering API. Could it be a licencing issue or a service not started on my dev environment perhaps? – Rob Stevenson-Leggett May 28 '12 at 20:08
  • Hmmm... if the information can be retrieved with the deprecated (not yet obsolete) API, it should also be available with the newer ones. Can you maybe update your question with an example of the old API that does work for retrieving this path? – Frank van Puffelen May 28 '12 at 20:21
  • Hi Frank, I haven't got the old API working in this particular case yet but this one: http://stackoverflow.com/a/10795084/4950 The Criteria API was just returning nothing, not even going to the DB according to SQL Profiler. – Rob Stevenson-Leggett May 29 '12 at 07:52

4 Answers4

5

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.

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
3

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.

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
Chris Summers
  • 10,133
  • 1
  • 19
  • 46
1

Try this:-

 BinaryMeta binaryMeta = b.GetBinaryMeta(queryStringId);
 if(binaryMeta != null) {
       VideoBinaryUrl = binaryMeta.URLPath;
 }
Siva Charan
  • 17,278
  • 8
  • 56
  • 89
1

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);
            }
        }
    }
Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
Rob Stevenson-Leggett
  • 33,849
  • 21
  • 84
  • 138
  • Aha, so it seems you were bitten by the default variant. I have the feeling something changed there in Tridion 2011, but haven't been able to figure out how it exactly affects the query building. – Frank van Puffelen May 29 '12 at 12:52