0

Currently I have a GrahpQL query with bunch of images returning src as "/-/media"

query:

field(name:"Image"){ ...on ImageField{src} } 

Result:

"Image": {
        "src": "/-/media/images/abc.ashx",
      },

Is there a way to get custom media prefix (without ~ or -. Just like "/customname/images...")?

2
  • The result you are receiving is the proper path for Sitecore to resolve it. If you want to change that to a custom path you may need to look into a solution involving a CDN. Commented Mar 23, 2022 at 22:02
  • Thank you @MichaelWest. Unfortunately we don't have a CDN setup.
    – Sun
    Commented Mar 25, 2022 at 12:29

2 Answers 2

1

Since we don't have a CDN url setup. I created this patch file and now I am getting results as expected.

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> 
<sitecore> 
 <settings> 
  <setting name="Media.RequestExtension"> 
   <patch:attribute name="value"></patch:attribute> 
  </setting> 
  <setting name="Media.MediaLinkPrefix"> 
   <patch:attribute name="value">customname</patch:attribute> 
  </setting> 
 </settings> 
 <customHandlers> 
  <handler trigger="/customname/" handler="sitecore_media.ashx"/> 
 </customHandlers> 
</sitecore> 
</configuration>

Now I am getting below results:

"Image": {
            "src": "/customname/images/abc.jpg",
          }
0

You can create a zz.CDN.enabler.config with the following settings to enable the CDN.

<setting name="Media.AlwaysIncludeServerUrl" value="true"/>
<setting name="Media.MediaLinkServerUrl" value="[you need to put the CDN url]"/>
<setting name="Media.AlwaysAppendRevision" value="false"/>
<setting name="MediaResponse.Cacheability" value="Public"/>
<setting name="MediaResponse.MaxAge" value="7.00:00:00"/>

and then web.config add the following setting it gives media urls a relevant extension like .jpg

<setting name="Media.RequestExtension" value=""/>
1
  • Thank you Sanjay and Sumit. Unfortunately we don't have CDN url setup.
    – Sun
    Commented Mar 25, 2022 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.