You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(functions): return binary media responses as a Blob - #2785
invoke() returns a Blob for common binary image, audio, video and font media types (PNG, JPEG, GIF, WebP, AVIF, BMP, TIFF, ICO, HEIC/HEIF, MP3, AAC, FLAC, Ogg, Opus, WAV, WebM, MP4, MPEG, QuickTime, OTF, TTF, WOFF, WOFF2, font collections), alongside the existing application/octet-stream and application/pdf cases. The types are listed in one set, and the invoke() TSDoc lists them.
Why was this change needed?
Response types without a dedicated branch fall back to response.text(). An Edge Function that returns an image, audio, video or font body therefore gives the caller a string in which every byte sequence that is not valid UTF-8 is replaced, so the original body cannot be recovered. In a local test, a 14-byte PNG body came back as a string that re-encodes to 24 bytes. #1757 fixed the same problem for application/pdf (supabase/supabase#18175).
Other types keep their existing decoding. image/svg+xml, audio/mpegurl and audio/x-mpegurl playlists, image/x-xbitmap and unknown image types are still read as text.
📸 Screenshots/Examples
// Edge FunctionreturnnewResponse(pngBytes,{headers: {'Content-Type': 'image/png'}})// Clientconst{ data }=awaitsupabase.functions.invoke('og-image')// before: string with replacement characters// after: Blob with the exact bytes
🔄 Breaking changes
For the newly supported binary media types, data is now a Blob instead of a string, as #1757 did for application/pdf. For bodies containing bytes that are not valid UTF-8, the previous string had already lost them. A function that sends text, such as base64, labelled with one of these types needs a text content type to keep receiving a string. The TypeScript signature is unchanged.
I have run pnpm nx format to ensure consistent code formatting
I have added tests for new functionality (if applicable)
I have updated documentation (if applicable)
📝 Additional notes
response-content-type.spec.ts checks exact bytes for 11 binary content types, including one with mixed case and a parameter, and checks that the SVG, M3U, XBM and unknown image/* cases stay text. Nine of the binary cases fail on master. pnpm nx test:ci functions-js passes (7 suites, 60 passed, 1 skipped), as do the supabase-js type, unit and module-resolution checks.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Summary
Summary by CodeRabbit
Bug Fixes
Function responses using common image, audio, video, font, PDF, and generic binary formats now preserve their original bytes instead of being interpreted as text.
Content type matching now handles uppercase and mixed-case values, including values with parameters.
Other formats, including SVG and unrecognized media types, continue to be returned as text.
FunctionsClient now uses a set of recognized binary media types to select response.blob(). It normalizes the response content type before matching. Other media types continue to use text parsing. Tests cover listed binary types, mixed-case content types with parameters, and unlisted types.
Priority: ➖ Normal
Change: Bug fix
Merge Risk:⚪ Minimal · up to 54460
The reviewed response handling has no identified issue that needs resolution before merge.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
This branch has not been deployed
No deployments
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
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.
🔍 Description
What changed?
invoke()returns aBlobfor common binary image, audio, video and font media types (PNG, JPEG, GIF, WebP, AVIF, BMP, TIFF, ICO, HEIC/HEIF, MP3, AAC, FLAC, Ogg, Opus, WAV, WebM, MP4, MPEG, QuickTime, OTF, TTF, WOFF, WOFF2, font collections), alongside the existingapplication/octet-streamandapplication/pdfcases. The types are listed in one set, and theinvoke()TSDoc lists them.Why was this change needed?
Response types without a dedicated branch fall back to
response.text(). An Edge Function that returns an image, audio, video or font body therefore gives the caller a string in which every byte sequence that is not valid UTF-8 is replaced, so the original body cannot be recovered. In a local test, a 14-byte PNG body came back as a string that re-encodes to 24 bytes. #1757 fixed the same problem forapplication/pdf(supabase/supabase#18175).Other types keep their existing decoding.
image/svg+xml,audio/mpegurlandaudio/x-mpegurlplaylists,image/x-xbitmapand unknown image types are still read as text.📸 Screenshots/Examples
🔄 Breaking changes
For the newly supported binary media types,
datais now aBlobinstead of a string, as #1757 did forapplication/pdf. For bodies containing bytes that are not valid UTF-8, the previous string had already lost them. A function that sends text, such as base64, labelled with one of these types needs a text content type to keep receiving a string. The TypeScript signature is unchanged.📋 Checklist
<type>(<scope>): <description>pnpm nx formatto ensure consistent code formatting📝 Additional notes
response-content-type.spec.tschecks exact bytes for 11 binary content types, including one with mixed case and a parameter, and checks that the SVG, M3U, XBM and unknownimage/*cases stay text. Nine of the binary cases fail on master.pnpm nx test:ci functions-jspasses (7 suites, 60 passed, 1 skipped), as do the supabase-js type, unit and module-resolution checks.