Images/edit HTTPError: Response code 415 (UNSUPPORTED MEDIA TYPE)

I am trying to use the v1/images/edit API, what I am doing is that I am passing my image to the backend as the documentation says.


so I pass it to the backend…

The problem is that I always get this error, I tried converting it from image to base64 and it doesn’t work either.

Any idea?

image / string / Required

The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.

https://beta.openai.com/docs/api-reference/images/create-edit

If you’re sending to edit endpoint and don’t also send a mask image, part of the image needs to be transparent.

Hope this helps.

I already did that, and I’m still getting the same error

Then likely the transparency isn’t correct somehow…

Is this any help?

ETA:

A thread with a similar problem with Python that had to do with how the PNG was saved originally.

What language are you using? Looks like React or some form of javascript?

nextjs, im asking the user to upload a file by input type=‘file’, then I send that file with formData() to my backend /api, and I place the file path into fs.createReadStream(path)

If the user uploads a malformed PNG, though, it still might not work.

I found this NextJS code that might help? They seem to be reading it a bit differently…

{
  const {fileName, maskFileName, prompt, n, size} = req.body;
  const result = await openai.createImageEdit(
    createReadStream(fileName) as unknown as File,
    createReadStream(maskFileName) as unknown as File,
    prompt,
    n,
    size,
  );
  res.status(200).json({ result: result.data.data });
}

I think the docs code only has a nodejs and cURL example…

I wonder if anyone’s put together a definitive list of the basics in all languages… Hrm…

Anyway, hope this points you in the right direction! Sorry I couldn’t be more helpful.

I uploaded this image and its not working
s

Is it 24 or 32 bit?

Did you have a look at the code I linked? Seems it’s slightly different to open the image with nextjs…