From f05759e51e417044787e71c7a9260c6a87f08aca Mon Sep 17 00:00:00 2001 From: AtharvGaur Date: Mon, 15 Dec 2025 14:47:32 +0530 Subject: [PATCH 1/4] feat(storage): add contentEncoding option to FileOptions interface --- packages/core/storage-js/src/lib/types.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/core/storage-js/src/lib/types.ts b/packages/core/storage-js/src/lib/types.ts index b4344c58a..7a4142229 100644 --- a/packages/core/storage-js/src/lib/types.ts +++ b/packages/core/storage-js/src/lib/types.ts @@ -88,6 +88,10 @@ export interface FileOptions { * the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`. */ contentType?: string + /** + * The `Content-Encoding` header value (e.g., `gzip`). + */ + contentEncoding?: string /** * When upsert is set to true, the file is overwritten if it exists. When set to false, an error is thrown if the object already exists. Defaults to false. */ From 25b5accd21543932d03bc5a393c9528689e900ff Mon Sep 17 00:00:00 2001 From: AtharvGaur Date: Mon, 15 Dec 2025 14:47:59 +0530 Subject: [PATCH 2/4] feat(storage): include content-encoding header in StorageFileApi methods --- packages/core/storage-js/src/packages/StorageFileApi.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core/storage-js/src/packages/StorageFileApi.ts b/packages/core/storage-js/src/packages/StorageFileApi.ts index 53ba2859a..b8e8ad5c0 100644 --- a/packages/core/storage-js/src/packages/StorageFileApi.ts +++ b/packages/core/storage-js/src/packages/StorageFileApi.ts @@ -124,6 +124,10 @@ export default class StorageFileApi { headers['cache-control'] = `max-age=${options.cacheControl}` headers['content-type'] = options.contentType as string + if (options.contentEncoding) { + headers['content-encoding'] = options.contentEncoding + } + if (metadata) { headers['x-metadata'] = this.toBase64(this.encodeMetadata(metadata)) } @@ -291,6 +295,9 @@ export default class StorageFileApi { body = fileBody headers['cache-control'] = `max-age=${options.cacheControl}` headers['content-type'] = options.contentType as string + if (options.contentEncoding) { + headers['content-encoding'] = options.contentEncoding + } } const data = await put(this.fetch, url.toString(), body as object, { headers }) From 851cddc4341af71c1ab5ceb7b1b82c116c37f4d1 Mon Sep 17 00:00:00 2001 From: AtharvGaur Date: Mon, 15 Dec 2025 14:48:15 +0530 Subject: [PATCH 3/4] test(storage): add unit test for Content-Encoding header in upload method --- .../core/storage-js/test/storageFileApi.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/core/storage-js/test/storageFileApi.test.ts b/packages/core/storage-js/test/storageFileApi.test.ts index 645de3e00..094e738c4 100644 --- a/packages/core/storage-js/test/storageFileApi.test.ts +++ b/packages/core/storage-js/test/storageFileApi.test.ts @@ -7,6 +7,7 @@ import ReadableStream from 'node:stream' import { StorageApiError, StorageError } from '../src/lib/errors' import BlobDownloadBuilder from '../src/packages/BlobDownloadBuilder' import StreamDownloadBuilder from '../src/packages/StreamDownloadBuilder' +import StorageFileApi from '../src/packages/StorageFileApi' // TODO: need to setup storage-api server for this test const URL = 'http://localhost:8000/storage/v1' @@ -34,6 +35,8 @@ const findOrCreateBucket = async (name: string, isPublic = true) => { const uploadFilePath = (fileName: string) => path.resolve(__dirname, 'fixtures', 'upload', fileName) + + describe('Object API', () => { let bucketName: string let file: Buffer @@ -851,5 +854,19 @@ describe('StorageFileApi Edge Cases', () => { expect(body).toBe(testFormData) expect(headers[testHeaderKey]).toBe(testHeaderValue) }) + + test('upload sets Content-Encoding when provided', async () => { + await storage + .from('test-bucket') + .upload('test-path', new Uint8Array([1, 2, 3]), { + contentType: 'application/octet-stream', + contentEncoding: 'gzip', + }) + + expect(mockPost).toHaveBeenCalled() + const [, , body, { headers }] = mockPost.mock.calls[0] + expect(headers['content-type']).toBe('application/octet-stream') + expect(headers['content-encoding']).toBe('gzip') + }) }) }) From 9900e8c3f1b2aa38166b36293765a0aab1350e7c Mon Sep 17 00:00:00 2001 From: AtharvGaur Date: Mon, 15 Dec 2025 14:58:46 +0530 Subject: [PATCH 4/4] fix(storage): support content encoding on uploads --- packages/core/storage-js/test/storageFileApi.test.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/core/storage-js/test/storageFileApi.test.ts b/packages/core/storage-js/test/storageFileApi.test.ts index 094e738c4..fccff8966 100644 --- a/packages/core/storage-js/test/storageFileApi.test.ts +++ b/packages/core/storage-js/test/storageFileApi.test.ts @@ -35,8 +35,6 @@ const findOrCreateBucket = async (name: string, isPublic = true) => { const uploadFilePath = (fileName: string) => path.resolve(__dirname, 'fixtures', 'upload', fileName) - - describe('Object API', () => { let bucketName: string let file: Buffer @@ -856,12 +854,10 @@ describe('StorageFileApi Edge Cases', () => { }) test('upload sets Content-Encoding when provided', async () => { - await storage - .from('test-bucket') - .upload('test-path', new Uint8Array([1, 2, 3]), { - contentType: 'application/octet-stream', - contentEncoding: 'gzip', - }) + await storage.from('test-bucket').upload('test-path', new Uint8Array([1, 2, 3]), { + contentType: 'application/octet-stream', + contentEncoding: 'gzip', + }) expect(mockPost).toHaveBeenCalled() const [, , body, { headers }] = mockPost.mock.calls[0]