+1
for what Sayantan said.
Now, This behavior avoids duplicacy of binaries and is default nature. It also appends width & height in some case (Ex: ballon-burner_tcm5-258_w1024_h311_n.jpg)
.
Little bit of background on this
The Default Finish Action Template contains a TBB called - Publish binaries for component
It uses a PublishBinariesComponent, which calls ConstructFileName of BinaryPublisher.
private static string ConstructFileName(Component mmComp, string variantId)
{
Regex re = new Regex(@"^(.*)\.([^\.]+)$");
string fileName = mmComp.BinaryContent.Filename;
if (!String.IsNullOrEmpty(fileName))
{
fileName = Path.GetFileName(fileName);
}
return re.Replace(fileName, string.Format("$1_{0}_{1}.$2", mmComp.Id.ToString().Replace(":", ""), variantId.Replace(":", "")));
}
This method returns the binary file name at Rendering -
engine.PublishingContext.RenderedItem.AddBinary()
. One of the overload method AddBinary(Stream, String, String, Component, String)
also give liberty to set filename of your choice but this is limited i believe.
Look at the code below:
If you see the else
part - ConstructFileName(mmComp, currentTemplate.Id)
is called when targetStructureGroupUri
is not null, this value comes from your parameter schema of Publish binaries for component
TBB.
if (targetStructureGroupUri == null)
{
....
Binary binary = engine.PublishingContext.RenderedItem.AddBinary(mmComp);
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();
....
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 = b.Url;
log.Debug(string.Format("binary is published to url {0}", publishedPath));
}
So if you write a TBB (Create your custom default finish action Template) and add it.. right after Publish Binary for Component TBB to process received Output from Publish binaries for component
TBB then you might have some chance. The output should have publishedPath
which is what you would need to get to your desired url.
Your Publish binaries for component
parameter schema has all the values i guess which is used in the final binary url. Specially sg_PublishBinariesTargetStructureGroup
value in your case.
There could be better ways indeed.