All things Shopify and commerce
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
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
Solved! Go to the solution
This is an accepted solution.
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
This is an accepted solution.
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