-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix for Edit Image content type requirement #979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix for Edit Image content type requirement #979
Conversation
…mFile` wrapper only does `application/octet-stream`.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #979 +/- ##
===========================================
- Coverage 98.46% 85.46% -13.00%
===========================================
Files 24 43 +19
Lines 1364 2270 +906
===========================================
+ Hits 1343 1940 +597
- Misses 15 308 +293
- Partials 6 22 +16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@sashabaranov I'm not sure how to fix this codecov failing CI check. It says there's a 13% drop in testing coverage but nothing I changed materially impacted tests. It seems to think there's more changes than what my PR made, maybe due to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the image content type issue for the OpenAI Edit Image endpoint by setting the content-type explicitly to "image/png" in the form builder.
- Replaces the default helper call with manual MIME header construction.
- Hardcodes "image/png" as the content type to address the endpoint's requirements.
func (fb *DefaultFormBuilder) createFormFile(fieldname string, r io.Reader, filename string) error { | ||
if filename == "" { | ||
return fmt.Errorf("filename cannot be empty") | ||
} | ||
|
||
fieldWriter, err := fb.writer.CreateFormFile(fieldname, filename) | ||
h := make(textproto.MIMEHeader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a comment to explain the manual MIME header construction with the hardcoded 'image/png' content type, so future maintainers understand this is specifically for the Edit Image endpoint fix.
h := make(textproto.MIMEHeader) | |
h := make(textproto.MIMEHeader) | |
// The "Content-Type" is hardcoded to "image/png" because this method is specifically | |
// used for the "Edit Image" endpoint, which requires PNG files. |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! Could I kindly ask for an integration test here? Without them it's really hard for me to verify multitude of coming changes
@@ -34,12 +36,22 @@ func (fb *DefaultFormBuilder) CreateFormFileReader(fieldname string, r io.Reader | |||
return fb.createFormFile(fieldname, r, path.Base(filename)) | |||
} | |||
|
|||
var quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to use backtics here!
@Static-Flow on the coverage note, could you try rebasing your branch on the latest master branch? |
Describe the change
PR to fix #967 and #601 The OpenAI Edit Image endpoint
/v1/images/edits
only accepts specific image formats as seen in error responses like so:status: 400 Bad Request, message: Invalid file 'image': unsupported mimetype ('image/jpeg'). Supported file formats are 'image/png'
. Even though the API docs say other types are supported https://platform.openai.com/docs/api-reference/images/createEdit:This is not true as of
4-28-25
I think because it is still stuck on DALLE mode which only allows PNGs.Describe your solution
Pretty simple fix really, replaced the call to the default helper method which only does
application/octet-stream
with the code the helper method calls and set the content-type toimage/png
Tests
I ran a modified version of the image example which calls the edit image endpoint instead using my forked version and it worked successfully.