Replacing an image programatically

Hi Folks, I'm a front end dev at BeFunky.com, we use Prismic for CMS, which is working great.

Is there a way to replace one image with another in the Media library programmatically? Maybe via an API request or something? Ideally we would like to replace an image in one spot and have it be updated on all pages where it is used. Or do I need to download all the Prismic JSON and do some sort of find and replace?

1 Like

Replying here as well and copying my Youtube comment in here as I'm not sure where to place feedback regarding a use case that has been mentioned in the Meetup yesterday.

I've asked about replacing assets rather than doing it manually through documents. My use case is that I have to update existing images every now and then as we have updates on our (physical) products so I get a request to replace a marketing image of an old one with a marketing image of a new one. I understand your point that simply replacing it might not always be the best solution (e.g. due to the focus of the image that you set depending on where it is placed on each page) but it would help immensely if I would at least see where the image is used.

At the moment with the asset search we have it is already a struggle for us to find images of products that need to be replaced so we end up basically scrolling through the whole list of assets and write down every file we see. I guess this process will go much smoother with the new asset manager, tagging and improved search so I'm not too worried about that. Once the images have been identified, I still have to go through every document that I suspect to have the image in it (or alternatively search it in the JSON data I guess). All in all it's just a very tedious task.

Hi @matthias.ackeret ,

These are very interesting ideas that you bring up and we have been thinking about these use cases.

We have been working on an assets API that accompanies our migration API, but it is in the early days of development/testing. Once it is in a stable state and the team has more time, this is something we will then take more time to consider, but like you said there are considerations to make for sizing and publishing etc. so we'll have to take our time with implementing anything that can cause break changes.

I'm tracking the idea for the team to see. If/when we have any updates we'll let you know here.

Thanks.

1 Like