There are multiple overrides of Engine.AddBinary()
to acieveachieve different things, mostly allowing you to publish variants of the multimedia Component, or to change the filename of the item published. So any of the overrides are considered a correct way to publish a binary. If you just want to publish the binary as is, you can use Engine.AddBinary(Item multimediaItem, TcmUri targetLocation)
.
The reason for the Component (1st argument) is the variant use cases, for example:
- you have a word document in your multimedia Component and want to publish it as a PDF file too, you can use the one of the overrides where you specify a binary array and change the filename (the extension part in this case).
- You will now have the same multimedia Component published as two variants, so the usage counter of the Component can be correctly updated (making sure all the variants are removed when the Page(s) & Component(s) that use this are unpublished.
The URL of the published binary is correctly retreived from the outcome of the Engine.AddBinary()
call, so in your case the value of the replace
variable. But note, this value will be different when previewing and publishing. The example you mention is a result from a preview (either through the CME or the Template Builder). If you would debug your TBB using the Publisher on an aactual render/publish action, you would get the real URL the binary will get on the specific published target.