0

The scenario is the following:

For a single component we're getting the html content from an external provider. Including images. For each image we have to call a separate endpoint of the external provider. In return we get the Binary data with the http header "content-type:image/jpeg.

So basically I have this link <img src="mydomain.com/-/city/images/test.jpg" />

But this image does not exist and never will be in Sitecore. Instead for every image that starts with "-/city" I need to get the image from somewhere else. My Idea was to overwrite the MediaProvider where I set the Url to an existing Media Item. Once that is assigned I want to call the endpoint and return the mediastream from my endpoint. I've followed this blog post: https://sitecorejumpstart.wordpress.com/2020/02/28/override-the-sitecore-media-provider/

But already failed here:

public override MediaRequest ParseMediaRequest(HttpRequest request) as I cannot change the called Url to something else in the request.

Any idea how or if this is doable at all? I'm using SC 9.1.1 btw with SxA

4
  • 1
    Maybe create a handler for -/city/* urls?
    – Marek Musielak
    Feb 22, 2021 at 13:43
  • One scenario that I have done is with SharePoint documents. I created a new media template with a field containing details relevant to SharePoint such as the full URL and document name and so on. Then my rendering variant simply generates the URLs that I care about. Feb 22, 2021 at 13:44
  • Agree with Marek here, I would avoid the Sitecore code and handle this yourself, esp since the prefix is not using the standard -/media prefix either.
    – jammykam
    Feb 22, 2021 at 21:34
  • Thank you! Will do so. Feb 23, 2021 at 6:23

1 Answer 1

1

You wrote in your question:

every image that starts with -/city I need to get the image from somewhere else

In my opinion, if Sitecore has nothing to do with those urls, let's not even try to handle it by Sitecore. That's a waste of resources only.

Instead, create a handler for -/city/* urls and register it in web.config. Something like this should do the trick:

<add verb="" path="-/city/*" type="My.Assembly.Namespace.CityMediaHandler, My.Assembly.Namespace" />

Potentially you will need to add /-/city/ to IgnoreUrlPrefixes:

<setting name="IgnoreUrlPrefixes" value="/-/city/|/sitecore/default.aspx|/trace.axd|...

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.