feat(storage): add content-encoding support for uploads
Add content-encoding support for uploads
🔍 Description
- Add
contentEncodingtoFileOptionsand apply theContent-Encodingheader for uploads and signed uploads when provided. - Ensure streaming / non-FormData uploads can declare gzip (or other) encodings.
- Add unit coverage verifying the header is sent.
What changed?
- Extended
FileOptionswith an optionalcontentEncodingfield. - Updated
StorageFileApiupload anduploadToSignedUrlto set theContent-Encodingheader whencontentEncodingis passed. - Added tests in
storageFileApi.test.tsto assert the correct headers are sent for uploads using streams/buffers.
Why was this change needed?
-
Storage currently doesn’t expose a way to set
Content-Encodingon uploads. -
This is required to support use cases where files are uploaded already compressed (e.g. gzip) from Edge Functions and should be served correctly in browsers.
-
Implements the feature requested in #1883.
-
No breaking changes. The new
contentEncodingoption is optional and only affects behavior when explicitly provided.
Thanks for the PR @Athaxv! This is a great feature request and the client-side implementation looks good.
However, the storage server's REST API (/object/* routes) doesn't currently handle the Content-Encoding header. The client will send it, but the server will ignore it.
Specifically, in the storage server:
-
fileUploadFromRequest()only extractscontent-type,cache-control,x-robots-tag, andx-metadataheaders - The
uploadObject()backend method doesn't have acontentEncodingparameter - The S3 Upload params don't include
ContentEncoding
The S3-compatible API routes (/s3/*) already support Content-Encoding, it's just the REST API that's missing this.
You can open a feature request on the supabase/storage repo to add Content-Encoding support to the REST API routes. Once that's implemented and released, we can merge this PR and the feature will work end-to-end.
You can reference this PR and issue #1883 in that request. The server-side changes would involve:
- Extracting
content-encodingheader infileUploadFromRequest() - Adding
contentEncodingparameter to theuploadObject()method - Passing
ContentEncodingto the S3 Upload params
I'll keep this PR open and we can revisit once the server-side support lands.