feat(storage): support content encoding uploads#2322
Conversation
There was a problem hiding this comment.
Pull request overview
Adds first-class contentEncoding support to the storage client’s upload flows so callers can preserve encoding metadata (e.g. gzip) when uploading pre-compressed assets, including via signed upload URLs.
Changes:
- Added optional
contentEncodingtoFileOptions. - Passed
contentEncodingthrough uploads: as acontent-encodingheader for raw bodies, and as acontentEncodingmultipart form field forBlob/FormData. - Added Jest tests validating
contentEncodingbehavior for bothupload()anduploadToSignedUrl().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/core/storage-js/src/lib/types.ts | Adds contentEncoding to the public upload options type. |
| packages/core/storage-js/src/packages/StorageFileApi.ts | Forwards contentEncoding through both standard and signed uploads (header vs multipart field depending on body type). |
| packages/core/storage-js/test/storageFileApi.test.ts | Adds test coverage ensuring contentEncoding is propagated for both raw and multipart upload bodies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| */ | ||
| contentType?: string | ||
| /** | ||
| * The `Content-Encoding` header value. Useful when uploading already-compressed file bodies, for example `gzip`. |
| if (typeof Blob !== 'undefined' && fileBody instanceof Blob) { | ||
| body = new FormData() | ||
| body.append('cacheControl', options.cacheControl as string) | ||
| if (options.contentEncoding) { | ||
| body.append('contentEncoding', options.contentEncoding) | ||
| } |
| const [, , body] = mockPost.mock.calls[0] | ||
| expect((body as FormData).get('contentEncoding')).toBe('gzip') | ||
| }) | ||
|
|
|
Thanks for the contribution @yashwanth8634, and for the clean, well-tested implementation. Before I can merge this on the client side, we need the storage server to actually honor
So as-is, this PR would advertise an option that has no effect, callers would assume their object has Would you be up for opening a feature request on https://github.com/supabase/storage proposing that the standard upload route (and ideally the S3-compat route too) persist A couple of smaller notes for when we do revisit:
Also FYI, this PR targets You can do this very easily.
|
This pull request adds support for specifying
contentEncodingvalues, such asgzip, when uploading files via the storage client. The change ensures that content encoding is passed through correctly during both standard uploads and signed URL uploads.What changed?
contentEncodingfield to theFileOptionsinterface.StorageFileApito passcontentEncodingthrough upload requests:content-encodingheader.Blob,File, orFormData, it includescontentEncodingas a form field.contentEncodingbehavior for bothupload()anduploadToSignedUrl().Why it changed
The storage client already supports related upload metadata such as
contentTypeandcacheControl, but did not expose a first-class way to setContent-Encoding.This is useful for pre-compressed assets, such as gzip-encoded files, where callers need the stored object to preserve the correct encoding metadata.
Closes #1883
How to test
Run the focused storage test:
cd packages/core/storage-js ../../../node_modules/.bin/jest test/storageFileApi.test.ts --runInBand --testNamePattern contentEncoding --watchman=false