Is there some way to override the RTE media picker to use the CDN domain rather than the relative Url that it uses at the moment?
A standard media picker control uses the proper CDN url e.g. http//cdn.example.com/media/234/image.jpg but using an image picked via the RTE still serves images from the local machine not the CDN url.
Thanks for coming back - but if I do that I seem to get the raw HTML rendered on the page - e.g.
<p><span class="FullSizeImage"><img id="__mcenew" src="/media/1087/dreamstime_l_28166563.jpg" alt="" data-id="1225"></span></p> <h3>Do take your shoes off</h3> <p>When entering temples, private homes, or even some shops and offices, take your shoes off. You’ll know when it’s appropriate to do so because you’ll see lines and piles of shoes outside the front door. Feet are considered the dirtiest part of the body in Thailand, and shoes even more so. Therefore, it’s considered a big no-no to point at anything with your feet, put your feet up on the table, or touch anyone with your feet.</p>
Also, you'll see from the above that the media url is still relative and doesn't seem to have picked up the CDN domain.
Sorry - still doesn't work. Media Urls added to the RTE using the media picker on the RTE editor are still relative and not using the CDN. Web.config settings
In the spirit of sharing, I've refactored your ParseMediaLinks function to update the main regexes. There's a couple of things that I found - anyway, here you go:
private static string ParseMediaLinks(string input)
{
var output = input;
var matchesImages = Regex.Matches(input, "<img(.*?)src=\"(?<url>/media/.*?)\"(.*?)(/?)>", RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
foreach (Match match in matchesImages)
{
string url = match.Groups["url"].Value;
var outputLink = string.Format("{0}{1}", GlobalHelper.GetCdnDomain(), url);
output = output.Replace(match.Groups["url"].Value, outputLink);
}
var matchesLinks = Regex.Matches(input, "<a(.*?)href=\"(?<url>/media/.*?)\"(.*?)>(?<content>.*?)</a>");
foreach (Match match in matchesLinks)
{
string url = match.Groups["url"].Value, content = match.Groups["content"].Value;
if (IsPlainText(content))
{
var outputLink = string.Format("{0}{1}", GlobalHelper.GetCdnDomain(), url);
output = output.Replace(match.Groups["url"].Value, outputLink);
}
}
return output;
}
Note that even with Simon's update (which works great by the way), that regex still relies on using "/media/" as part of the URL. If you define a different virtualRoot in FileSystemProviders.config, it won't find the URL to replace it properly. I changed mine manually to follow my naming convention, but it would be helpful to incorporate the virtualRoot element into the regex in a future version.
Override RTE media picker urls
Hi,
Is there some way to override the RTE media picker to use the CDN domain rather than the relative Url that it uses at the moment?
A standard media picker control uses the proper CDN url e.g. http//cdn.example.com/media/234/image.jpg but using an image picked via the RTE still serves images from the local machine not the CDN url.
Ideas?
Thanks
Simon
Hi Simon,
You can use
ParseContent
method and pass the value of the RTE.Have a look at the function in the GitHub repository here: https://github.com/AliSheikhTaheri/AST-Amazon-S3/blob/master/AST%20Amazon%20S3/Helper/ContentHelper.cs#L7
example in a cshtml
Hope the above code helps.
Cheers
Ali
Hi Ali,
Thanks for coming back - but if I do that I seem to get the raw HTML rendered on the page - e.g.
Also, you'll see from the above that the media url is still relative and doesn't seem to have picked up the CDN domain.
Ideas?
Thanks
Simon
Hi Simon,
In order to fix the raw html use this:
To get CDN domain, do you have
useCDN
andcdnDomain
setup in your web.config?Cheers
Ali
Hi Ali,
Sorry - still doesn't work. Media Urls added to the RTE using the media picker on the RTE editor are still relative and not using the CDN. Web.config settings
Template code:
Image url in the content
Not the CDN.
Any more ideas?
Thanks
Simon
Ali,
Found the problem - you're using this regex to find the images to parse
However, the image tag from the RTE media picker is this:
Which doesn't match your Regex.
Hi Ali,
In the spirit of sharing, I've refactored your ParseMediaLinks function to update the main regexes. There's a couple of things that I found - anyway, here you go:
Thanks
Simon
Hi , How will I get the latest dll or code.
The package is is throwing error.
Note that even with Simon's update (which works great by the way), that regex still relies on using "/media/" as part of the URL. If you define a different virtualRoot in FileSystemProviders.config, it won't find the URL to replace it properly. I changed mine manually to follow my naming convention, but it would be helpful to incorporate the virtualRoot element into the regex in a future version.
is working on a reply...