Hello,
this is my first message so I hope to be in the right section. Many of my SKU's share identical images so I would like to avoid duplicate images on my server. I do everything through the API, so my idea is to:
1- create the SKU without image (with a POST to /V1/products)
2- calculate the md5sum of the associated image before uploading it via the API
3- check whether this image (renamed with its md5sum) already exists on the server
3a- if NO: upload the image and attach it to the SKU (with a POST to /V1/products/:sku/media)
3b- if YES: attach the image already on the server to the SKU
But I can't achieve step "3b":
- If I PUT to /V1/products/:sku with the correct image path as "file" but an empty "content" object; I receive a response 400 with error "The image content is invalid. Verify the content and try again."
- If I PUT to /V1/products/:sku with the correct image path as "file" and correct "content" (base64_encoded_data, type and name); I receive a response 200 but with an empty "media_gallery_entries": [] (so the image is not attached even if the response is 200)
- If I POST to /V1/products/:sku/media with the correct image path as "file", correct data in "content" (base64_encoded_data, type and name) and "id" as the media/:entryId for the same image in another sku; I receive a response 400 with error "The new media gallery entry failed to save."
- If I POST to /V1/products/:sku/media with the correct image path as "file", correct data in "content" (base64_encoded_data, type and name) and an empty "id"; I receive a response 200 with the id of a new media/:entryId. Unfortunately, this action creates a duplicate of the image on the server (with _x appended to the filename)
Same problem is described here: https://magento.stackexchange.com/questions/275420/magento-2-rest-api-copy-image-from-another-sku
I am using Magento 2.3.4 and I am out of ideas.
Can someone tell me how I can "reuse" an existing image and thus avoid duplicate images on the server?
Thanks for any help!