3

Whenever some of the unconfigured MIME types are sent for publishing our publisher is hanging up and someone has to manually kill the process to get it running.

To get rid of this, I am trying to understand DD4T and want to know how to fix this. Currently we are using ECL library for resolving multimedia items from an external asset management system. We either need to fail publishing or publishing should succeed rather than hanging up the publisher.

Update:

Below is the code I have updated. I have hard coded variant ID for the time being. Still the publisher is hanging up. Am i missing something?

protected virtual void PublishItem(Item item, TcmUri itemUri, out int ImageWidth, out int ImageHeight)
        {

            ImageWidth = 0;
            ImageHeight = 0;
            Stream itemStream = null;
            // See if some template set itself as the applied template on this item
            TcmUri appliedTemplateUri = null;
            if (item.Properties.ContainsKey(Item.ItemPropertyTemplateUri))
            {
                appliedTemplateUri = new TcmUri(item.Properties[Item.ItemPropertyTemplateUri]);
            }

            try
            {
                string publishedPath;
                if (targetStructureGroupUri == null)
                {
                    log.Debug("no structure group defined, publishing binary with default settings");
                    Component mmComp = (Component)engine.GetObject(item.Properties[Item.ItemPropertyTcmUri]);
                    // Note: it is dangerous to specify the CT URI as variant ID without a structure group, because it will fail if you publish the same MMC from two or more CTs!
                    // So I removed the variant ID altogether (QS, 20-10-2011)
                    log.Debug(string.Format("publishing mm component {0} without variant id", mmComp.Id));
                    //Binary binary = engine.PublishingContext.RenderedItem.AddBinary(mmComp);

                    string fileName = ConstructFileName(mmComp, currentTemplate.Id);
                    using (Stream stream = CreateTemperaryFileStream())
                    {
                        item.GetAsStream().CopyTo(stream);
                        Binary binary = engine.PublishingContext.RenderedItem.AddBinary(stream, fileName, "1024X1024", mmComp, mmComp.BinaryContent.MultimediaType.MimeType);
                        publishedPath = binary.Url;
                    }
                    log.Debug(string.Format("binary is published to url {0}", publishedPath));
                }
                else
                {
                    Component mmComp = (Component)engine.GetObject(item.Properties[Item.ItemPropertyTcmUri]);

                    string fileName = ConstructFileName(mmComp, currentTemplate.Id);
                    StructureGroup targetSG = (StructureGroup)engine.GetObject(targetStructureGroupUri);
                    itemStream = item.GetAsStream();
                    if (itemStream == null)
                    {
                        // All items can be converted to a stream?
                        log.Error(String.Format("Cannot get item '{0}' as stream", itemUri.ToString()));
                    }
                    //byte[] data = new byte[itemStream.Length];
                    //itemStream.Read(data, 0, data.Length);
                    //itemStream.Close();
                    log.Debug(string.Format("publishing mm component {0} to structure group {1} with variant id {2} and filename {3}", mmComp.Id, targetStructureGroupUri.ToString(), currentTemplate.Id, fileName));
                    //Binary b = engine.PublishingContext.RenderedItem.AddBinary(item.GetAsStream(), fileName, targetSG, currentTemplate.Id, mmComp, mmComp.BinaryContent.MultimediaType.MimeType);

                    //publishedPath = engine.AddBinary(itemUri, appliedTemplateUri, targetStructureGroupUri, data, fileName);
                    using (Stream stream = CreateTemperaryFileStream())
                    {

                        itemStream.CopyTo(stream);

                        Binary b = engine.PublishingContext.RenderedItem.AddBinary(stream, fileName, targetSG,
                                                                                           currentTemplate.Id, mmComp,
                                                                                           mmComp.BinaryContent
                                                                                                 .MultimediaType
                                                                                                 .MimeType);
                        publishedPath = b.Url;
                    }

                    log.Debug(string.Format("binary is published to url {0}", publishedPath));
                }
                log.Debug("binary published, published path = " + publishedPath);
                item.Properties[Item.ItemPropertyPublishedPath] = publishedPath;
            }
            finally
            {
                if (itemStream != null) itemStream.Close();
            }
        }
  • can you elaborate a bit on unconfigured MIME types, do you mean they are not known MIME types for SDL Tridion or something else? Also how are you handling the ECL items, is Tridion Publishing them using the AddBinary() method, or are they just resolved to a direct link or template fragment? – Bart Koopman Nov 19 '13 at 9:05
  • They are not known MIME types for tridion and you are right they are published using AddBinary() method. – Guest19876 Nov 19 '13 at 9:29
  • Are you using the standard DD4T template building blocks, like Generate Dynamic Page/Component, Add binaries for Page/Component? Or did you create your own TBBs? – Quirijn Nov 19 '13 at 9:36
  • @Kris so you are calling IContentLibraryMultimediaItem.GetContent(), could it be that the content stream is just incredibly large and the Publisher isn't really hanging but getting a lot of data? Last week my Resolve ECL Items TBB was changed to save the stream to a file temporarily for performance reasons, see the CreateTemporaryFileStream() method. – Bart Koopman Nov 19 '13 at 9:39
  • @Quirijn I have customized generate dynamic page\component and binary publisher code but finally we are calling PublishMultimediaComponent() method of BinaryPublisher class. – Guest19876 Nov 19 '13 at 9:56
0

An ECL multimedia component is only a stub. It does not give access to the actual content. You will need to call the ECL api. The following code could serve as a starting point. I haven't tested this, don't even know for sure if it will compile. You have been warned :)

    protected override void PublishItem(Item item, TcmUri itemUri)
    {
        IEclSession eclSession = SessionFactory.CreateEclSession(engine.GetSession());
        IEclUri eclUri = TryGetEclUriFromTcmUri(itemUri);
        if (eclUri != null)
        {
            IContentLibraryContext eclContext = eclUri.GetContentLibrary(eclUri);
            IContentLibraryMultimediaItem eclItem = eclContext.GetItem(eclUri) as IContentLibraryMultimediaItem;
            IContentResult result = eclItem.GetContent(null); // assuming we don't need to pass in any template attributes
            Stream itemStream = result.Stream;
            if (itemStream == null)
            {
                log.Error(String.Format("Cannot get item '{0}' as stream", itemUri.ToString()));
                return;
            }
            log.Debug(string.Format("publishing mm component {0} to structure group {1} with variant id {2} and filename {3}", mmComp.Id, targetStructureGroupUri.ToString(), currentTemplate.Id, fileName));

            Component mmComp = (Component)engine.GetObject(item.Properties[Item.ItemPropertyTcmUri]);
            string fileName = ConstructFileName(mmComp, currentTemplate.Id);
            StructureGroup targetSG = (StructureGroup)engine.GetObject(targetStructureGroupUri);
            Binary b = engine.PublishingContext.RenderedItem.AddBinary(itemStream, fileName, targetSG,
                                                                                   currentTemplate.Id, mmComp,
                                                                                   mmComp.BinaryContent
                                                                                         .MultimediaType
                                                                                         .MimeType);
            publishedPath = b.Url;
            return;
         }
        // this is not an ECL item, continue normally

    }
0

Using CreateTemperaryFileStream() solved the issue with a bit of changes in size limits in web config of HTTP upload and deployer config file. Thanks to Bart & Quirijn.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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