Repository navigation
Conversation
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Checklist
devbranch.Closes #29948.Title Prefix
Summary
Fixes #29948 where generated images returned as bare base64 (
b64_jsonfrom OpenAI, GeminibytesBase64Encoded, and compatible image generation backends) are always saved asimage/pngandgenerated-image.pngregardless of their actual image format.Details:
sniff_image_mime(data: bytes) -> strto inspect image magic bytes (JPEGFF D8 FF, PNG89 50 4E 47, WebPRIFF....WEBP, GIFGIF87a/GIF89a, BMPBM, TIFF) with a PIL fallback and safe default toimage/png.get_image_data()to inspect bare base64 decoded bytes usingsniff_image_mime()instead of unconditionally hardcodingimage/png. Also added fallback sniffing when data URIs provide genericoctet-streamheaders, and replaced character-strippinglstrip('data:')withremoveprefix('data:')to prevent corrupted MIME strings.IMAGE_FILE_EXTENSIONSto support.gifand.bmpalongside.jpg,.png, and.webp.upload_image()to checkIMAGE_FILE_EXTENSIONSbeforemimetypes.guess_extension()so that JPEG files are consistently named.jpginstead of Python's default.jpe.Testing
sniff_image_mimeandget_image_datalocally across JPEG, PNG, WebP, GIF, and BMP test images encoded as bare base64 and data URIs.image/png.ruff format --checkandruff checkmatching the repository's GitHub Actions CI workflow (.github/workflows/backend.yaml). All checks passed with zero errors.Changelog Entry
Fixed
image/png(issue: Generated images always saved as image/png regardless of actual format (mime hardcoded for b64_json responses) #29948).Contributor License Agreement