Copied image disappears when original image is deleted

Hi i have the following issue:

I have an ecommerce type site with the following simple data schema:
order
order items
product

each order contains multiple order items, which in turn contains exactly one product.
When creating a new order item I save the product’s price, as well as image from the product to the order item data type in order to preserve it.

However, I noticed that the image is actually the same image and not a copy. Now my product database is actually synched from airtable using make so the image is frequently updated. In order not to create multiple images, I delete the old image file when there is a new image in the dataype. This causes the image to disappear from the order item data type as it seems when I copy the image from one data type to another it just saves a reference to the original file.

Can anybody suggest me a solution/alternative implementation?

Cheers,
Konrad

Don’t put onto the Order data type a field that is image, instead, reference the image field from the product data type (which is getting updated) as you already have the product data type related to the order data type anyway.

thanks for your reply. The issue I have with that is if I use that URL in an order confirmation mail and I change the image later on, the email won’t show an image anymore as it will have been deleted. That is why I wanted to “snapshot” the image at the time of order into the order data type field.

A snapshot is an image. An image needs to be in your file manager for an S3 bucket URL to be created and available for it.

Oh, I didn’t see that bit of detail in the original post.

Then create a field that is list of images to store all images previously used in emails…or come up with some other novel approach to keep the images in your database and file manager…or expect that you most likely will have users opening an email the day it arrives, so just don’t change the image for a day or two after you send out the emails.

But sounds like you might have already found the approach you will use for your need of keeping the image file because you sent emails with the image.

You could play around with your email by not using the image URL and instead just pass through the image and see if that makes any difference to the continued display of the image in the mail once you delete it from your file manager.

But, there are plugins that can create a png from elements, so maybe you implement that and take the ‘snapshot’ of the original image and then send in the email the png (I would expect that the generated png is added to your file manager and therefore Amazon S3 bucket). This approach will lead to a lot of double up of images though as you will likely be sending more than one email on different days for the same product.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.