Skip to content

fix(functions): return binary media responses as a Blob - #2785

Open
mkantautas wants to merge 1 commit into
supabase:masterfrom
mkantautas:fix/functions-binary-response
Open

mkantautas wants to merge 1 commit into
supabase:masterfrom
mkantautas:fix/functions-binary-response

Conversation

@mkantautas

Copy link
Copy Markdown

🔍 Description

What changed?

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 Function
return new Response(pngBytes, { headers: { 'Content-Type': 'image/png' } })

// Client
const { data } = await supabase.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.

  • This PR contains no breaking changes

📋 Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • 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.

@mkantautas
mkantautas requested review from a team as code owners October 23, 2026 03:43
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4664aab6-8a2a-4662-abb6-bb2b863fe542
📥 Commits

Reviewing files that changed from the base of the PR and between 817c2c1 and 5446038.

📒 Files selected for processing: 2
  • packages/core/functions-js/src/FunctionsClient.ts
  • packages/core/functions-js/test/spec/response-content-type.spec.ts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant