1

我正在尝试检索作为动态组件演示文稿发布的多媒体组件文件的二进制 URL。

我可以在 Broker 数据库的 Binaries 表中看到 Url,但我似乎无法使用以下任一代码位获取二进制 url:

使用 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 (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);
    }
}

我可以使用 ComponentMetaFactory 加载组件元数据。

关于为什么我无法加载二进制元的任何想法?我在正确的轨道上吗?

4

4 回答 4

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.

于 2012-05-28T18:46:24.080 回答
3

您是否有理由不使用二进制链接来获取链接对象到您想要的二进制文件的特定变体?请记住,任何 DCP 都可能呈现多媒体组件的多种变体。然后,您可以从 Link 对象获取二进制文件的 URL。

在文档中查找 BinaryLink 以获取更多详细信息。

于 2012-05-29T12:13:47.063 回答
1

我对代码做了一个 SQL Profiler,发现这是因为我部署了我的测试应用程序,它没有调用代理。在实际的 Tridion Published 站点中运行代码确实命中了数据库,但它为 variantId 列传递了值“[#def#]”。

我现在可以使用以下代码:

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);
            }
        }
    }
于 2012-05-29T10:08:30.197 回答
1

尝试这个:-

 BinaryMeta binaryMeta = b.GetBinaryMeta(queryStringId);
 if(binaryMeta != null) {
       VideoBinaryUrl = binaryMeta.URLPath;
 }
于 2012-05-28T17:45:23.017 回答