How to create ImageEdit from ImageData?

Hi, I am working with one application and wanted to create Edit an image. However, I have ImageData. I tried to convert ImageData in to .png image as described here “OpenAI Platform”.

const buffer = imageData; = “image.png”;

However, I am getting an error “image’ is the required property”. I tried many ways to resolve it but I could not. I am using JS. Anybody can help?

Best way I’ve found is to use the OpenAI library for image endpoints, especially editing.

If you show your code, we might be able to help more.

This is my code. I think, there is mistake in sending JSON data. I cannot figure it out.

  let buffer = imageData; = 'image.png';

const sendHttpRequest = (method, url, data) => {
    return fetch(url, {
      method : method,
      body : JSON.stringify(data),
      headers: data? {"Content-Type": "multipart/form-data", "Authorization": "Bearer" + " " + api_key} : {}
    }).then(response => {
      if(response.status >= 400){
        return response.json().then(errResData => {
          const error = new Error('Something went wrong');
 = errResData;
          throw error;
      return response.json();
  const sendData = (image,mask,query,n,size) => {
    sendHttpRequest("POST", "", {
      "image": image,
      "mask": buffer,
      "prompt": query,
      "n" : n,
      "size": size,
    }).then(responseData => {
    }).catch(err => {

I also tried to send data as a FormData but getting same error.

const form_data = new FormData();
form_data.append("mask", buffer);
form_data.append("prompt", 'Change hair color to pink');

At the end you found a way to solve this problem?

You must send a 32-bit png file, not buffered image raw data.

It is sent in multipart/form-data as image/png MIME

Javascript dox:

You are right but I wanted to send buffered image not .png file.

I want to send the AI a sample of some cloth so it can feel which is softest for making a dress, but that is also not a data format that the API accepts.

I do not know that you can check softness from image or not but you can send imageData. It is written in their documentation.

you have to send images as a blobLike

formdata.append(‘image’, new Blob([buffer],{type:‘image/png’})