Loading
Prepare for Email to Become the Default Login ExperienceRead More
Get Started with B2C Commerce
Honor Job Hostnames in Image URL Generation

Honor Job Hostnames in Image URL Generation

In a job context, such as a catalog export, B2C Commerce can generate image URLs that use the job hostnames from your site's aliases file. These URLs match your other job-generated URLs, so you don't need custom code to correct the hostname.

When B2C Commerce runs a job, such as a catalog export, there's no storefront request to determine the hostname. Instead, B2C Commerce relies on the job hostnames in your site's aliases file. Previously, when the following MediaFile Script API methods ran within a job context, they didn't apply the job-hostnames configuration from the aliases file. Instead, the methods fell back to the default instance hostname. As a result, image URLs in feeds and other job output sometimes used a different hostname than the pipeline URLs. To correct the hostname, merchants had to write custom code.

Now, jobs generate image URLs for using the same hostname as your other job-generated URLs.

Example
Example

Suppose that your storefront is www.example.com, and your aliases file defines that as the job hostname. You run a nightly catalog export job that generates a product feed, and each product includes an image URL.

  • Without this behavior, the job can't determine which hostname to use, so it falls back to the default instance domain. Your feed goes out with image URLs like https://prd.my.commercecloud.salesforce.com/.../shoe.jpg.
  • With this behavior turned on, the job uses the job hostname from your aliases file instead: https://www.example.com/.../shoe.jpg.

The image links now match your storefront's hostname, so external channels show your product images correctly. You no longer require custom code to replace the hostname.

This behavior applies to these MediaFile Script API methods when they run within a job context:

Method Description
MediaFile.getImageURL() Generates a URL for the media file.
MediaFile.getAbsImageURL() Generates an absolute URL for the media file.
MediaFile.getHttpImageURL() Generates a standard HTTP URL for the media file.
MediaFile.getHttpsImageURL() Generates a secure HTTPS URL for the media file.

If you want this behavior for your environment, contact Salesforce Support.

Note
Note Before you turn on this behavior, review any custom code that replaces hostnames in your job-generated image URLs. After you turn it on, these URLs use your configured job hostnames, so you no longer need that custom code.
 
Loading
Salesforce Help | Article