Stuck on the edit endpoint in java

I am stuck trying to get the edit endpoint to work in java. i can get the image generation endpoint to work and get back the new image path. but with the edit endpoint i cant get the file upload to work.

I keep getting this error:

{ “error”: { “code”: null, “message”: “‘image’ is a required property”, “param”: null, “type”: “invalid_request_error” }}

I have two png images in the Pictures folder on android device. in the code we check if the file exists then we use multipart form to upload data, but it does work.

here is the current java code:

File imageFile = new File(ai_pngimage);
File maskFile = new File(ai_pngmask);
if (!imageFile.exists() || !maskFile.exists()) {
Log.d(“yoyo”, “RZB_OPENAI_Image Errors the files DONT EXIST”);
}

byte imageData = Files.readAllBytes(Paths.get(ai_pngimage));
byte maskData = Files.readAllBytes(Paths.get(ai_pngmask));

// Construct multipart request body
String CRLF = “\r\n”;String twoHyphens = “–”;

try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream()))
{
// Write image file
wr.writeBytes(twoHyphens + boundary + CRLF);
wr.writeBytes(“Content-Disposition: form-data; name="image"; filename="image.png"” + CRLF);Log.d(“yoyo”, “Content-Disposition: form-data; name="image"; filename="image.png"” + CRLF);
wr.writeBytes(“Content-Type: image/png” + CRLF);
wr.writeBytes(CRLF);
wr.write(imageData);
wr.writeBytes(CRLF);

// Write mask file
wr.writeBytes(twoHyphens + boundary + CRLF);
wr.writeBytes("Content-Disposition: form-data; name=\"mask\"; filename=\"mask.png\"" + CRLF);Log.d("yoyo", "Content-Disposition: form-data; name=\"mask\"; filename=\"mask.png\"" + CRLF);
wr.writeBytes("Content-Type: image/png" + CRLF);
wr.writeBytes(CRLF);
wr.write(maskData);
wr.writeBytes(CRLF);

// Write other parameters
wr.writeBytes(twoHyphens + boundary + CRLF);
wr.writeBytes("Content-Disposition: form-data; name=\"prompt\"" + CRLF);
wr.writeBytes(CRLF);
wr.writeUTF(ai_prompt);
wr.writeBytes(CRLF);

wr.writeBytes(twoHyphens + boundary + CRLF);
wr.writeBytes("Content-Disposition: form-data; name=\"n\"" + CRLF);
wr.writeBytes(CRLF);
wr.writeInt(nValue);
wr.writeBytes(CRLF);

wr.writeBytes(twoHyphens + boundary + CRLF);
wr.writeBytes("Content-Disposition: form-data; name=\"size\"" + CRLF);
wr.writeBytes(CRLF);
wr.writeUTF(ai_size + "x" + ai_size);

// End of multipart request
wr.writeBytes(twoHyphens + boundary + twoHyphens + CRLF); 
//wr.flush();
}

int responseCode = connection.getResponseCode();

StringBuilder response = new StringBuilder();

:thinking:

are you actually sending an image too, or just the mask?

image AND a mask
512px X 512px
both <4MB size

here is the code:
// Write image file
wr.writeBytes(twoHyphens + boundary + CRLF);
wr.writeBytes(“Content-Disposition: form-data; name=“image”; filename=“image.png”” + CRLF);Log.d(“yoyo”, “Content-Disposition: form-data; name=“image”; filename=“image.png”” + CRLF);
wr.writeBytes(“Content-Type: image/png” + CRLF);
wr.writeBytes(CRLF);
wr.write(imageData);
wr.writeBytes(CRLF);

// Write mask file
wr.writeBytes(twoHyphens + boundary + CRLF);
wr.writeBytes("Content-Disposition: form-data; name=\"mask\"; filename=\"mask.png\"" + CRLF);Log.d("yoyo", "Content-Disposition: form-data; name=\"mask\"; filename=\"mask.png\"" + CRLF);
wr.writeBytes("Content-Type: image/png" + CRLF);
wr.writeBytes(CRLF);
wr.write(maskData);
wr.writeBytes(CRLF);

i think its really quiet ridiculous how difficult they have made it just to upload two images and get them processed. they could add support to give image urls instead of uploading them each time, would save heck of bandwidth. i just used another third party api that does the same thing and i clocked that in like 1/10th of the time its taken to get to the stage im at with openai edit endpoint

OK this has been resolved now as had to use okhttp3