Repository navigation
fix(storage): apply empty transform check to download and getPublicUrl - #2219
Conversation
@supabase/auth-js
@supabase/functions-js
@supabase/postgrest-js
@supabase/realtime-js
@supabase/storage-js
@supabase/supabase-js
commit: |
mandarini
left a comment
There was a problem hiding this comment.
Hi @oniani1, thank you so much for contributing to Supabase! 💚
This is a clean, correct fix. The Object.keys guard is exactly the right pattern, and it's consistent with what was done in createSignedUrl in #2162. The diff is minimal and easy to verify.
One small thing before I can merge: could you add two tests alongside this fix, similar to the one added in #2162 for createSignedUrl? The existing test at line 124 of storageFileApi.test.ts is a good template -- we'd just need the same shape for download() and getPublicUrl(). Something like:
download() with empty transform object does not use render endpointgetPublicUrl() with empty transform object does not use render endpoint
Once those are in, this is good to merge. Thanks again for the thorough write-up in the issue and for following through with the fix!
mandarini
left a comment
There was a problem hiding this comment.
Sorry, one more change @oniani1 ! The getPublicUrl test looks great. The download test needs one small adjustment. Because the test uploads sadcat.jpg (a real JPEG), hitting /render/image/authenticated/ with an empty query string would still return the image successfully, so res.error being null does not actually prove the correct endpoint was used. Could you swap the uploaded file for the file.txt fixture that's already in the test fixtures? A non-image file will 422 if it accidentally routes through the render endpoint, making res.error === null a meaningful assertion:
it('download with empty transform object does not use render endpoint', async () => {
const txtFile = await fsp.readFile(uploadFilePath('file.txt'))
const txtPath = `testpath/file-${Date.now()}.txt`
await storage.from(bucketName).upload(txtPath, txtFile)
const res = await storage.from(bucketName).download(txtPath, {
transform: {},
})
expect(res.error).toBeNull()
expect(res.data?.size).toBeGreaterThan(0)
})Once that's updated, this is good to merge. Thanks for the quick turnaround!
Use file.txt instead of sadcat.jpg so a non-image file would 422 if it accidentally routes through the render endpoint, making the assertion meaningful.
|
Hey @mandarini, the file.txt swap is in f139868 -- should be good to go now. Let me know if anything else needs changing! |
This PR updates @supabase/*-js libraries to version 2.103.2. **Source**: supabase-js-stable-release **Changes**: - Updated @supabase/supabase-js to 2.103.2 - Updated @supabase/auth-js to 2.103.2 - Updated @supabase/realtime-js to 2.103.2 - Updated @supabase/postgest-js to 2.103.2 - Refreshed pnpm-lock.yaml --- ## Release Notes ## v2.103.2 ## 2.103.2 (2026-04-15) ### 🩹 Fixes - **auth:** include Cloudflare error codes in NETWORK_ERROR_CODES ([#2239](supabase/supabase-js#2239)) - **auth:** remove Prettify wrapper from exported types for TypeDoc expansion ([#2250](supabase/supabase-js#2250)) - **misc:** add explicit return types to toJSON methods for JSR compat ([#2252](supabase/supabase-js#2252)) - **storage:** remove client-side signed URL render endpoint normalization ([#2249](supabase/supabase-js#2249)) ### ❤️ Thank You - Katerina Skroumpelou @mandarini - Vansh Sharma @Vansh1811 ## v2.103.1 ## 2.103.1 (2026-04-15) ### 🩹 Fixes - **auth:** add toJSON to AuthError for correct JSON serialization ([#2238](supabase/supabase-js#2238)) - **postgrest:** handle bigint rpc ([#2245](supabase/supabase-js#2245)) - **storage:** add toJSON to StorageError for correct JSON serialization ([#2246](supabase/supabase-js#2246)) - **storage:** apply empty transform check to download and getPublicUrl ([#2219](supabase/supabase-js#2219)) ### ❤️ Thank You - oniani1 - Vaibhav @7ttp This PR was created automatically. Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
…dpoint (#1551) ## Summary An empty or default `TransformOptions()` was routing `download()` and `getPublicUrl()` through the `/render/image/` endpoint unnecessarily. Previously the decision was based on `transform != null`, so any `TransformOptions` instance, even one with all-null fields, switched to the render path. Now routing only switches to the render endpoint when the transform options actually produce query parameters. **Outcome:** implemented (bug fix) ## Behavior - `download(path)` without transform uses `/object/` endpoint - `download(path, transform: TransformOptions())` with empty transform uses `/object/` endpoint - `download(path, transform: TransformOptions(width: 200))` uses `/render/image/authenticated/` endpoint - Same logic for `getPublicUrl()` ## Tests Added unit tests in `packages/storage_client/test/basic_test.dart` covering empty vs actual transform routing for both `download()` and `getPublicUrl()`. All storage_client unit tests pass. ## Reference - Linear: SDK-878 - supabase-js PR: supabase/supabase-js#2219 (commit `993bb5fc`) ## Compliance matrix `storage.file_buckets.download_with_transform` and `storage.file_buckets.get_public_url` remain `implemented`; this fix brings their routing behavior in line with supabase-js, so no status change was required.
Fixes #2218
PR #2162 fixed
createSignedUrl()to reject empty transform objects, butdownload()andgetPublicUrl()still use the oldtypeof options?.transform !== 'undefined'check. Sincetypeof {} !== 'undefined'istrue, passing an empty transform object routes requests through/render/image/instead of/object/, causing 422 errors for non-image files.This applies the same
Object.keyscheck fromcreateSignedUrlto both methods.