I have 1 000 images stored in a file, in Content Builder. Each image corresponds with a user. Image names are the users' id.

When an email is sent to a given user, I want his photo to be displayed in the email.

I would like to know if an ampscript function allows me to display the image whose name matches with my user's id.

I found the functions ContentImageById and ContentImageByKey but what I would like to use is the image name, not the ID or the key.

Thanks a lot for your help !

1 Answer 1


You have multiple options:

Option 1: I understand that you have a lot of images, and the option 2 is not very suitable for your use case.

You can use the "Predictable File URLs" fonctionnality on your account. You can enable it by going to Setup > Platform Tools > Content Builder > Content Builder Settings

Since the image names are your users ids, each image would have a unique id. This way, you can predict your images urls and call them directly on your email using something similar to:

<img src="CONCAT('https://yourdomain.com/lib/',CONCAT(@SubscriberKey,'.png/jpeg/..'))"/>

By default, Content Builder generates a unique identifier for the uploaded file's name. Predictable URLs use the uploaded file name as the end of the URL path for the published file. This feature applies only to files uploaded after enablement. Upload files with unique filenames. Filenames can include alphanumeric characters, hyphens, underscores, and periods.

Option 2: You can use the ContentBlockByName function.

Returns content contained in the specified stored content block or code snippet from Content Builder, including the Image Block type.


%%=ContentBlockByName("Content Builder\Weekly Portfolio")=%%

You can use it with CONCAT('Content Builder\', _SubscriberKey) to automate the selection of the image..

Keep in mind that this function will only work with an Image block and not with a simple Image:

Image type:
enter image description here

Image block type:

enter image description here

To create an image block, go to Content Builder > Create > Content Blocks > Image Block

Check out the documentation here:


  • Thanks Rachid ! I also tried thtis function but it looks like it is not working with Image Block, it only works with text / layout blocks...
    – Clothilde
    Commented Oct 25, 2019 at 10:14
  • Try using ampscript image functions like ContentImageByKey(). developer.salesforce.com/docs/…. For this you would have to use the contactkey rather than the name. Commented Oct 25, 2019 at 12:15
  • @Clothilde, I think that you are testing with an Image and not an Image Block. Check out my answer, I've updated it to explain the difference.. Commented Oct 25, 2019 at 12:17
  • @RachidMamai the thing is I have 1700 photos, is there a way to easily create these 1700 Image Blocks ?
    – Clothilde
    Commented Oct 25, 2019 at 14:54
  • @Clothilde, I've updated my answer accordingly. Check out the first option and tell me if it suits your needs Commented Oct 25, 2019 at 15:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .