2

When publishing to the filestore, we can add the following to the cd_storage_config

<Item typeMapping="Binary" itemExtension=".pdf" storageId="pdfFileLocation"/>

and the PDF will be published to the folder specified in the node

<Storage Type="filesystem" Class="com.tridion.storage.filesystem.FSDAOFactory" Id="pdfFileLocation" defaultFilesystem="false">
                <Root Path="\\pdfs\" />
</Storage>

My question is ... is this possible to do when we are publishing to a broker database?

3
  • 1
    Do you mean... only some file types ending up in the DB? I think you can bind it to the DB by using the correct Storage bindings... but not sure anymore. Easily tested, I think.
    – Nuno Linhares
    Sep 17, 2021 at 5:51
  • 1
    Hey Nuno - my understanding is that we can divert files to a specific folder using the typeMapping and itemExtension but it seems this is only possible in the filestore. Given the broker stores the path anyway it seems odd that it wouldn't be possible; however, when I add the node in the DB Storage element then publishing itself fails. I may log this with support as I believe it should work OOTB. Sep 22, 2021 at 14:24
  • That's a good one. We can store paths in Database for pages... but binaries, I believe will indeed all end up in the same "binary path". There may be some trickery possible at render time (changing the binary path somehow) but not sure about it.
    – Nuno Linhares
    Sep 23, 2021 at 7:30

2 Answers 2

2

The response from Tridion Support confirmed that this is not supported for database publishing:

documentation for the root element and path attribute says they're used for the filesystem storage provider. So unfortunately it looks like this isn't possible without additional customization work. https://docs.rws.com/816112/100911/sdl-tridion-sites-9-5-main-documentation/root

If I'm honest I understand why it likely wasn't in the core in the past but as the Tridion Cloud instance doesn't allow file publishing (and the general advice is to not publish to the filestore anyway) I really would have hoped the response would have been pro-active.

1

Mark, not sure if you considered using custom Template Building Blocks. Although not a quick solution, in the custom TBB, we should be able to update the root path just for PDFs by calling the Engine.AddBinary() method and specifying the path (Structure Group) where you'd like the PDFs to be published.

So, something like this in the TBB should deploy only the PDFs to the path /pdfs if the SG has the title pdfs, and other binaries would end up in the standard binary path.

public override void Transform(Engine engine, Package package)
{
    Component component = (Component) Engine.GetObject(Package.GetByName(Package.ComponentName).GetAsSource().GetValue("ID"));
    var binaryComponents = ExtractBinaryCompents(component);
    
    // Structure group to publish PDFs
    TcmUri targetStructureGroupUri = new TcmUri("tcm:x-xxx-4");

    foreach (var binaryComponent in binaryComponents)
    {
        if (binaryComponent.BinaryContent.MultimediaType.MimeType.Equals("application/pdf"))
        {
            using (var input = new MemoryStream(binaryComponent.BinaryContent.GetByteArray()))
            {
                engine.AddBinary(binaryComponent.Id, null, targetStructureGroupUri, 
                    binaryComponent.BinaryContent.GetByteArray(), binaryComponent.BinaryContent.Filename);
            }
        }
    }
}

And in the broker DB, the path of PDFs would be updated.

enter image description here

1
  • 1
    You are correct Sab and this is a good solution usually but in this case we really want(ed) to avoid custom code if possible. This is likely the fallback option - as you'll see below, now it's confirmed that it will not work in the Broker database OOTB (oddly). Sep 24, 2021 at 14:21

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.