Yeah, I got the same issue for two months and can only upload via file upload. Wasted lots of time, can’t add any images through my own api (file server).
Make sure the system serving up the images (S3 in my case, but could be any file server) has the full content-type header of “image/jpeg”. S3 was defaulting to just “image” for unknown reasons.
Contact Shopify and ask them to clear your store’s image cache. Apparently they cache these even if they fail to get assigned to the product. This process takes about 36hrs, be sure to wait at least that long until you try to save a URL or it will get cached again.
But still getting the same issue with error “File Extension Doesn’t Match The Format Of The File”
I was able to solve this by reconvert the image to png/jpeg and save it again (by turn images into base64 string and turn back into images, this is ridiculous but it works lol).
Conversion code is down below, written in go.
func Base64ToPng(data string) (err error) {
idx := strings.Index(data, ";base64,")
if idx < 0 {
return errors.New("invalid image")
}
ImageType := data[11:idx]
unbased, err := base64.StdEncoding.DecodeString(data[idx+8:])
if err != nil {
return errors.New("cannot decode base64")
}
r := bytes.NewReader(unbased)
switch ImageType {
case "png":
case "jpeg":
im, err := jpeg.Decode(r)
if err != nil {
return errors.New("bad jpeg")
}
buf := new(bytes.Buffer)
if err := png.Encode(buf, im); err != nil {
return errors.New("unable to encode png")
}
r = bytes.NewReader(buf.Bytes())
}
im, err := png.Decode(r)
if err != nil {
return errors.New("bad png")
}
f, err := os.OpenFile("PATH_TO_SAVE_IMAGE", os.O_WRONLY|os.O_CREATE, 0777)
if err != nil {
return errors.New("cannot save file to disk")
}
png.Encode(f, im)
return nil
}
There’s only limit resource online in regards to this issue and the response message from shopify api is quite unclear.
Hope this will help anyone suffering from this issue, I’ve being dealing with this for about 2 months, but finally solved it.
{“data”:{“fileAcknowledgeUpdateFailed”:{“files”:null,“userErrors”:[{“code”:null,“field”:[“fileIds”],“message”:“File with id gid://shopify/MediaImage/XXX is not in the READY state.”}]}},“errors”:null
Hi, I had the same issue, but adding header “image/jpeg” to custom media service worked perfectly! Could be the reason why it didn’t work for you is that you used “images/jpeg” instead of “image/jpeg”?