Contentful logo

Contentful Community

Swapping an image without changing the url

We’ve added some images via the Media GUI. We’ve then linked to those images from other places using the URL of the image itself:

Our problem is that we’d like to change the assets for one of these photos, but we don’t want to break every place we’ve referenced the image (forum posts, blog comments, etc.).

Is this possible to do?

1 Like

Hey @brandon1,

I assume the the URL is in the format of https://images.contentful.com/<spaceId>/<assetId>/...? (i.e. the value of fields.file.url from the asset endpoint)

Then good news, you don’t have to worry!

Contentful stores those images indefinitely, so that you can have multiple versions of the same asset. When you update the image, the URL portion after the asset ID will change to a different unique value. So every request to the old URL will still behave as expected.

Best,
Stephan

thanks @stephan.schneider.

What i’m hoping for is to be able to change the image at a specific url. That is, to change the asset and have all the existing URLs point to the new asset.

Is this possible? And can I do it via the GUI?

Oh okay, so the other way around - sorry, I miss-understood that.

I don’t think that’s possible - it contradicts the concept of immutable versioning.

If you always want to display the latest version, it usually involves some scripting - for example via our JS SDK. There you can retrieve the latest asset and get the fields.file.url property.

I understand this is not possible in scenarios like a forum post, where you only embed an images URL. But on the other hand it preserves the information for later readers, instead of changing the context over time.

There are potential ways to work around, but this depends on your use-case - for example high-availability proxy/redirect servers. But don’t underestimate the effort to do it properly! You should be really sure that there’s no way around.

1 Like

Got it-that makes sense. So it sounds like referencing the direct file as I’m doing is a bit of a back door. I suspect the effort/tradeoffs of a redirect server would make it easily not worth it.

Thanks very much for explaining this to me!

1 Like

@stephan.schneider
@brandon1

did you found ways to have a stable url media today ?

Entries url can have stable urls, but not medias. Would be really amazing to upload an image on Contentful, and be able to change the image in contentful without changing the url of the contentful media.

But on the other hand it preserves the information for later readers, instead of changing the context over time.

Forum is the wrong example, putting an image and be able to easily change it is the real use case. It’s impossible without having “stable” urls, and being able to change the image the url is pointing on.