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();