Contentful logo

Contentful Community

Reference image by ID only

Let’s say that I have an asset like https://images.ctfassets.net/hq8sy8wk8n0y/37eSunfyJZb5Sz5X0B2shv/7198bb933d53a3c6ba7918a54c50ae12/rtaImage.jpeg. This asset requires the space ID, asset ID, asset token, and file name in order to be retrieved.

The asset ID is stable, but the token and filename can change, leading to a new link. Is there a way to link to an image using only the stable image ID? If there was, then I would not need to sync assets to get the token/file name.

Hi @sb8244, the asset URL is unique and not static; every time you upload a new file, the asset URL will change.
As you have pointed out, the asset ID doesn’t change, so if you query the asset ID via API, you can always get the most updated asset URL.

Thanks Alma.

I’m trying to avoid queries in the API as I want to guarantee there’s never ever downtime of content. Basically—I preload everything into my database and then present that to my interface. I’m using the assets API with an updatedAt filter to sync down the assets.

I realized that I can take the approach of serving a path like “/images/contentful/ABCDEF” and then redirect to the image that’s identified via ABCDEF. That will serve the purpose of giving me a static link URL while also having it update dynamically.