Metafields and media/images

Topic summary

Need to attach internal timestamps to product images uploaded via the Admin API to decide when to update images. Current workaround stores a JSON map in a product-level metafield, but it feels misaligned since the data isn’t on the image itself.

Key constraint: Shopify does not support metafields directly on images/media, so metadata cannot be attached to image objects.

Suggested workarounds: embed the timestamp in image alt text or in the filename. An example API payload for setting alt text was provided, and using a timestamped filename was also proposed for update checks.

Limitation: Alt text cannot be used because it’s surfaced on the storefront. The original poster indicates they’ll likely continue using the product metafield JSON approach despite it being cumbersome.

Outcome/status: No native solution identified; no platform change. A participant invited the poster to continue the discussion via email. The thread remains open with no definitive resolution.

Summarized with AI on December 16. AI used: gpt-5.

I have a use case where I need to associated extra data to an image I upload through the admin api. The use case is that I have an internal time stamp so I know when the image was updated internally. Ideally, when uploading the image, I would like to add that data to the image, the timestamp for example (I could get away with the originalSource). If I have something from my internal system, then I know if I should update the image or not by comparing the dates

Currently I am using a metafield on the product to store, i json, the images that I last updated, but this doesn’t feel right as data (metafield) is not attached to the image

Using metafields on the image/media would make sense to me, but I can’t see that being available. Am I missing something?

Thanks

Grant

Hey @GrantDB ,

You’re correct that Shopify currently does not allow metafields to be attached directly to images or media files.

Use Product Media Alt Text or Filename as Metadata:

One simple workaround is embedding your timestamp or identifier inside the alt text or filename of the uploaded image.

Include timestamp in alt text:

When uploading the image via the Shopify Admin API, set the alt text with your internal timestamp (e.g., image-alt-text-20241022T102500).

Example API request:

json:

{
  "product_image": {
    "attachment": "base64_encoded_image_data_here",
    "alt": "Updated on 2024-10-22T10:25:00"
  }
}

Use the filename to track updates:

Name your file like: product-image-20241022T102500.jpg.

When uploading, use the filename to determine whether an update is required by checking the timestamp embedded in the file name.

If I was able to help you, please don’t forget to Like and mark it as the Solution!

Best Regard,

Rajat Sharma

Thanks for this. We use the alt text on the front end of the site, so that wont work. Looks like the approach I do now, where I store the data in a metafield at the project level (as json) reference that, is probably the most flexible way, if cumbersome

Thanks

Grant

Could you please send me a message via email so we can discuss this further?

Thanks